0

I try to pick a value from a dropdown using selenium webdriver, but I get only errors.

I just want to select Ubuntu 16.04 from the OS Dropdown. I tried to click at the dropdown and then on the Ubuntu 16.04 element (There are 3 in the source code). I tried the wait.until method, but nothing succeed.

from selenium.webdriver.support.select import Select
from selenium import webdriver

url = 'https://clients.hostwinds.com/buycloud/289'
driver = webdriver.Firefox()
driver.get(url)
firstname = driver.find_element_by_name("firstname").send_keys('First')
lastname = driver.find_element_by_name("lastname").send_keys('Last')
email = driver.find_element_by_name("email").send_keys('mail@example.com')
password = driver.find_element_by_name("password").send_keys('123456789')
submit = driver.find_element_by_css_selector("#signup > div:nth-child(1) > div:nth-child(2) > form:nth-child(1) > div:nth-child(4) > div:nth-child(1) > div:nth-child(1) > input:nth-child(1)").click()
## next page
state = Select(driver.find_element_by_name("state")).select_by_index(2) ## works fine
## Here the problem begins: I need to choose Ubuntu 16.04 but all of my attemts failed

os = driver.find_element_by_xpath('//*[@id="inputConfigOption337"]')
os.location_once_scrolled_into_view
Select(os).select_by_index(5)

I get the following error:

selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view

BenT
  • 3,172
  • 3
  • 18
  • 38
Baks Golder
  • 1
  • 1
  • 1
  • Use explicit wait before accessing element. – KunduK Aug 26 '19 at 19:52
  • hi KunduK, I already tried os = ui.WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#select2-inputConfigOption337-result-qo6s-8975'))) os.click(), but this did not work. – Baks Golder Aug 26 '19 at 19:55
  • Are you sure that the second SELECT is visible? Some SELECTs are hidden permanently and just hold settings while a different UI gathers the data and some SELECTs are hidden until something is selected on the page, etc. – JeffC Aug 26 '19 at 20:58
  • Yes I am, the dropdown menu opens and I can see the options in the browser dev tools. – Baks Golder Aug 26 '19 at 21:01

1 Answers1

0

Reference the linked post that addresses the thrown scrolling error: Scrolling to element using webdriver?

I encountered this problem using Selenium with Firefox and Python. I ended up using the scrollIntoView method for Firefox as the other options didn’t have consistent behavior when I tested them. (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView).

Conrad
  • 91
  • 2
  • 8