1

I'm writing a bot in Python - Selenium that needs to choose things in a drop-down Select menu. The website in question seems to be initializing it's select drop down items with only 1 value: 1. My wait command

wait.until(EC.visibility_of_element_located((By.TAG_NAME, "select")))

won't cut it for this, it will only see the initial option of 1.

So I tried to wait until a 2nd option appears under it's select

wait.until(lambda d: d.find_elements(By.CSS_SELECTOR, 'option:nth-child(2)'))

but that always times out. This confuses me because this code executes fine:

wait.until(lambda d: d.find_elements(By.CSS_SELECTOR, 'option:nth-child(1)'))

Why am I timing out? I can see selects with 10 options as soon as the page is loaded. I've also tried Expected Conditions looking for the value or text of 2:

wait.until(EC.text_to_be_present_in_element_value((By.TAG_NAME, "option"),'2'))

times out

wait.until(EC.text_to_be_present_in_element_value((By.TAG_NAME, "option"),'1'))

has no trouble finding an option element with a value of 1.

I've tried a lot of iterations on this. Am I not understanding how wait commands and expected conditions are supposed to work?

  • It's hard to say what the issue might be without some experimentation. Perhaps the DOM is changing dynamically over time? Perhaps the second value isn't considered "visible" until the drop-down is expanded and scrolled to the correct position? etc – Kache Jun 07 '23 at 20:12
  • Are you able to share the url, and show us where the problem is happening? – Josh Heaps Jun 07 '23 at 20:38
  • I've got it now. It wasn't just not visible, it wasn't updating the options at all until the drop down menu is clicked on. – Fuzzy Fuzzballs Jun 07 '23 at 20:58

0 Answers0