简体   繁体   中英

Dynamic elements with Selenium and Python

I'm trying to fill a small form with Selenium, but it has dynamic elements that it doesn't let me capture in any way. In this link you can see the form: https://www.asefasalud.es/

形式

I have tried almost all the search elements, to capture the object, but none of them work.

driver.find_element_by_xpath("//*[contains(@id, 'inputDiafnac')]").get(0).send_keys("2")
driver.find_element_by_xpath("//*[contains(@id, 'inputDiafnac')]").send_keys("2") 
driver.find_element_by_xpath("//input[@id='inputDiafnac1']").send_keys("2")
driver.find_element_by_css_selector("#inputDiafnac1").send_keys("2")
driver.find_element_by_id("inputDiafnac1").send_keys("2")

最终结果

I don't know if there is another way to capture these elements, thank you.

I found something I think might work.

driver.switch_to.frame(driver.find_element(By.CSS_SELECTOR, "[name='calcular-seguro-medico']"))
driver.find_element_by_id("inputDiafnac1").send_keys("2")

Once you are done with elements inside this frame, you will need to switch back to the top level frame using

driver.switch_to.default_content()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM