0

I'm facing the following issue with Selenium:

Quotation Web Page

I've successfully completed the fields "Origen" and "Destino", however, the values ​​after the script occurs, disappear.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time


#Opciones navegacion
options = webdriver.ChromeOptions()
options.add_argument('--start-maximized')
options.add_argument('--disable-extensions')

driver_path = "C:/Users/Diego/Downloads/chromedriver.exe"
driver = webdriver.Chrome(driver_path, chrome_options = options)
 

#Iniciar en la pantalla 2
#driver.set_window_position(2000,0)
driver.maximize_window()
time.sleep(1)

#Inicializamos el navegador
driver.get('https://www.starken.cl/cotizador')

WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input#rc_select_6"))).send_keys('SANTIAGO')
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input#rc_select_7"))).send_keys('VINA DEL MAR')

I'll be thankful for any suggestion.

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

2 Answers2

1

These <input>s are ant based input boxes with a role of combobox which generates from which you have to select one.

To send the character sequence SANTIAGO to the element and select it from the auto-suggestions you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Code Block:

    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//div[text()='Origen:']//following::div[1]//span[@class='ant-select-selection-search']/input[@class='ant-select-selection-search-input']"))).send_keys('SANTIAGO')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,"//div[@title='SANTIAGO']/div[@class='ant-select-item-option-content' and text()='SANTIAGO']"))).click()
    
  • Browser Snapshot:

www_starken_cl_cotizador

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

Sometimes with dropdowns, a user input is required to confirm the selection can be mouse click or the enter button. I went for the latter. I also added some time to your wait function as it took longer for the page to load where I am, and the wait expired. This is only a "wait for up to" not a "wait for."

It's also worth mentioning if your input results in multiple items, you may need to make a further selection; i.e. which item from those results?

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time


#Opciones navegacion
options = webdriver.ChromeOptions()
options.add_argument('--start-maximized')
options.add_argument('--disable-extensions')

#driver_path = "C:/Users/Diego/Downloads/chromedriver.exe"
driver = webdriver.Chrome()
 

#Iniciar en la pantalla 2
#driver.set_window_position(2000,0)
driver.maximize_window()
time.sleep(1)

#Inicializamos el navegador
driver.get('https://www.starken.cl/cotizador')
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input#rc_select_6"))).send_keys('SANTIAGO' + u'\ue007' )
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input#rc_select_7"))).send_keys('VINA DEL MAR' + u'\ue007')
Shawn Ramirez
  • 796
  • 1
  • 5
  • 10