0

When I send text manually, suggestion area provided by first textbox , it works fine. But when I send the text using selenium library it cannot able to select the option from suggestion area, although that option is present inside the textbox. Is there any one who can help me out of that.

enter image description here

import time
from selenium.webdriver.support.ui import Select
path=r"C:\Users\AbdulRehman\Downloads\chromedriver_win32\chromedriver.exe"
# driver =  webdriver.Chrome(path)
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())

driver.get("https://www4.sii.cl/mapasui/internet/#/contenido/index.html")


try:
    element = WebDriverWait(driver, 1000).until(
        EC.presence_of_element_located((By.XPATH, '//*[@id="ng-app"]/body/div[5]/div/div/div[3]/div/button'))
         )
    element.click()
    print("prints its working fine now ..")
    
    element = WebDriverWait(driver, 1000).until(
        EC.presence_of_element_located((By.XPATH,'//*[@id="titulo"]/div[8]/i'))
         )
    element.click()
    
#     element = WebDriverWait(driver, 1000).until(
#         EC.presence_of_element_located((By.XPATH,'//*[@id="rolsearch"]/div[2]/div[1]/input'))
#          )

#     element.send_keys("PEDRO AGUIRRE CERD"+Keys.ENTER)

#     search = WebDriverWait(driver, 60).until(
#         EC.visibility_of_element_located((By.XPATH, '//*[@id="rolsearch"]/div[2]/div[1]/input'))
#     )
#     search.send_keys("EL MONTE" + Keys.ENTER)
#     time.sleep(3)
    search = WebDriverWait(driver, 60).until(
    EC.visibility_of_element_located((By.XPATH, '//*[@id="rolsearch"]/div[2]/div[1]/input'))
    )
    ActionChains(driver).click(on_element=search).send_keys("EL MONTE").send_keys(Keys.ENTER).perform()

    suggestion = WebDriverWait(driver, 60).until(
    EC.visibility_of_element_located((By.XPATH, '//strong[text()="EL MONTE"]'))
    )
    suggestion.click()
#     auto_complete = driver.find_elements_by_xpath('//*[@id="rolsearch"]/div[2]/div[1]/input')
#     auto_complete[0].click()
#     auto_complete.send_keys(Keys.RETURN)
#     element.send_keys("somehting in text")
#     search =  driver.find_element_by_xpath().click()
    
#     search.send_keys(Keys.RETURN)
    search_1 =  driver.find_element_by_xpath('//*[@id="rolsearch"]/div[2]/div[2]/input')
    search_1.send_keys("PEDRO AGUIRRE CERDA")
    search_1.send_keys(Keys.RETURN)

    search_2 =  driver.find_element_by_xpath('//*[@id="rolsearch"]/div[2]/div[3]/input')
    search_2.send_keys("somehting in text")
    search_2.send_keys(Keys.RETURN)
    
    print("Its also working now ......")
    
    time.sleep(3)
except Exception as e:
    print(e)
    driver.quit()


undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Abdul Rehman
  • 167
  • 2
  • 14

1 Answers1

0

The desired element is a Angular element, so to send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

  • Using XPATH:

    driver.get('https://www4.sii.cl/mapasui/internet/#/contenido/index.html')
    WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Aceptar']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//i[@data-ng-click='mostrarBusquedaRol()']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@data-ng-include, '/mapasui/common/_content/busqueda-rol.html')]//div[@id='rolsearch']//label[contains(., 'Comuna')]//following::input[1]"))).send_keys("PEDRO AGUIRRE CERD" + Keys.ENTER)
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

mapasui

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352