0

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/

form

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")

terminal result

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

5
  • 1
    Do not use the screenshot for the results which you can add simply as text. it makes difficult to understand the question and it result in less response to the question. Commented Apr 8, 2021 at 13:35
  • is the date picker always displayed on the page or is it displayed only after you click/invoke something? Commented Apr 8, 2021 at 13:42
  • The problem is that the elements you want are inside of what essentially acts like an IFRAME but isn't actually an IFRAME tag. <object type="text/html" name="calcular-seguro-medico" ... sandbox="allow-same-origin allow-scripts allow-forms allow-top-navigation" data="https://www.asefasalud.es/seguros/1.0/tarificador/#!/HomeWeb/" frameborder="0" id="iFrameResizer0"> I've never seen this before and am not sure how to handle it. I would start by trying the typical switch to IFRAME methods available but somehow I don't expect them to work. Commented Apr 8, 2021 at 15:12
  • Which button has to be clicked to see this form? Commented Apr 8, 2021 at 15:18
  • @vitaliis None, you just scroll down some Commented Apr 8, 2021 at 15:19

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

10 Comments

[name='calcular-seguro-medico'] is not unique
@vitaliis It doesn't have to be unique, the one you want just has to be first in the DOM. Also, the other match is inside that OBJECT tag so Selenium can't even see it (yet).
Ok, I thought this would work better .caja_tarificador>[name='calcular-seguro-medico']
I don't know this site at all. I generally start with the simplest locator I can come up with and use it until I find that it doesn't work sometimes. When that happens, I start digging into what is going on with the page when it's failing and when it's not failing and try to come up with a locator that works in both cases. Most times it just works all the time but when it doesn't, it can turn into an iterative process.
@Dev I inspected the desired element and scrolled up expecting to find an IFRAME. I found something that initially looked like an IFRAME but was instead an OBJECT tag... which I had never seen before. On closer inspection, it looks very similar to an IFRAME and apparently acts like an IFRAME, has a #document container inside like an IFRAME, etc.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.