Home > Net >  Dynamic dropdowns Selenium webdriver Python
Dynamic dropdowns Selenium webdriver Python

Time:11-10

Recently started with selenium in python and so far only element I have problems with are Dynamic dropdowns. For example on webpage under Subjects and State and City. How to handle these elements that are not visible in DOM. Can please someone can show me how they would solve example mentioned above.

For subjets it failes on this line:

class SwitchToFrame():

def test1(self):
    baseUrl = "https://demoqa.com/automation-practice-form"
    driver = webdriver.Chrome()
    driver.get(baseUrl)

    wait = WebDriverWait(wait = WebDriverWait(driver, timeout=10, poll_frequency=1)
    element = wait.until(expected_conditions.element_to_be_clickable((By.XPATH, "//div[@id='subjectsContainer']/div")))
    element.send_keys("English")

CodePudding user response:

Here I proceeded to click the first option in Subject after inputting the English. Also if you do check the driver.page_source you can actually see the elements inside. It disappears after the handling of the input tag.

wait=WebDriverWait(driver, 10)
driver.get("https://demoqa.com/automation-practice-form")
element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#subjectsInput")))
element.send_keys("English")
print(driver.page_source)
elem=wait.until(EC.element_to_be_clickable((By.ID, "react-select-2-option-0")))
driver.execute_script("arguments[0].click()", elem)

Imports

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