0

I am very new to Selenium so any help would be appreciated! I am trying to click the button "continue" in this page and it kept showing me:

"NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[id="bktContinue"]"}". 

How do I get it to click "continue"?

Code trials:

url="https://www.exteriores.gob.es/Consulados/toronto/en/ServiciosConsulares/Paginas/Consular/Visados-Schengen.aspx"
driver.get(url)
continue_link = driver.find_element(By.PARTIAL_LINK_TEXT, 'HERE')
continue_link.click()
driver.implicitly_wait(15) 
l=driver.find_element(By.ID,'bktContinue')

Snapshot of the HTML:

enter image description here

Here's the HTML I want it to click on:

<div id="dialog-confirm" title="Important Notice / Important Notice" style="font-size: 15px; background-color:#F3F5F7; height: 100%; width: 94%; box-sizing: border-box; color:black !important;">
<div style="text-align: center;">
    <span style="color: #ff0000; font-weight: bold;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">ATTENTION READ THIS MESSAGE CAREFULLY</font></font></span>
</div>
<br>
<div style="text-align: justify;">
    <div style="text-align: justify;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        • Enter the data requested, correct and complete. </font></font><br>
        <br><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        • Do not use initials for the identifying fields or we will reject your request. </font></font><br>
        <br><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        • </font></font><span style="text-decoration: underline"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">The request for a minor's passport renewal must be made with the minor's passport data. </font></font></span><br>
        <br><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        • The information you provide is the one that will appear in the passport. </font><font style="vertical-align: inherit;">Pay attention. </font></font><br>
        <br><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        Those appointments with incomplete or incorrect data will be canceled by the system. </font></font><br><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        A person whose identity cannot be verified will not be able to access the facilities, having to request a new appointment with correct identification data.</font></font><br>
        <br>
    </div>
    <br>
    <div style="text-align: justify; font-weight: bold;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        CONTINUING CONSTITUTES ACCEPTANCE OF THE ABOVE INDICATED RULES.
    </font></font></div>
</div>
<br>
<div id="bktContinue" style="text-align: center;">
    <div style="color: #ffffff; padding: 5px 10px; background-color: #99cc00; display: inline-block;"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">
        CONTINUE
    </font></font></div>
</div>

Snapshot of the element:

enter image description here

This is what I currently have. To get to the website I am having trouble with, you have to go in this website first: https://www.exteriores.gob.es/Consulados/toronto/en/ServiciosConsulares/Paginas/Consular/Visados-Schengen.aspx

Then click "book your appointment here"

How do I get it to click "continue" after this?

Tiny MML
  • 11
  • 1
  • 1
    I don't see the button `continue` anywhere can you add the `HTML` for that element you want to click ? – Akzy Feb 09 '23 at 07:24
  • Clicking on _`Book your appointment HERE`_ opens a new tab which doesn't renders at my end. Update the question with the relecant text based HTML. – undetected Selenium Feb 09 '23 at 12:41
  • Updated with the HTML. The fifth last line has the "bktContinue" that I want to click on – Tiny MML Feb 09 '23 at 19:20

2 Answers2

0

Try using this CSS selector instead:
continue_div = driver.find_element(By.CSS_SELECTOR,'#bktContinue > div')
My assumption is that the reason the continue button is not being pressed, is because the real element that should be clicked is the div inside of the element with the ID bktContinue.

Also another tip: It's possible that you're not clicking the correct link at this line:

continue_link = driver.find_element(By.PARTIAL_LINK_TEXT, 'HERE')
continue_link.click()

Because you're looking for a link element that contains the text 'HERE', there are 4 elements that match this criteria, so your scriptelement might be clicking another link where the #bktContinue is not on the next page and this might also be leading to a NoSuchElementException.

Romek
  • 284
  • 2
  • 10
  • 1
    it also might be due to that OP does not wait for the page load. The elements might not even be there yet. – Rolandas Ulevicius Feb 09 '23 at 10:59
  • That's true, he's using an implicit wait but the line is below the first call to find an element, i would recommend using explicit waits anyways. – Romek Feb 09 '23 at 11:01
  • I tried the CSS selector but it still gave me "NoSuchElementException". I also checked and the first click opened the correct page that I wanted to open. – Tiny MML Feb 09 '23 at 21:38
  • I also tried adding in explicit wait as suggested here, but it gave me `TimeoutException` . By waiting implicitly for 15 seconds I could see the page loaded fully before it returned the `NoSuchElementException`. Not sure if this is how it works – Tiny MML Feb 09 '23 at 21:45
0

To click on the element with text as CONTINUE you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#bktContinue font"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='bktContinue']//font[contains(., 'CONTINUE')]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried the explicit wait, but got "TimeoutException", although on the page I can see that the page has fully loaded – Tiny MML Feb 09 '23 at 21:34
  • @TinyMML See as per the HTML you provided the [xpath](https://i.stack.imgur.com/POO1M.png) is perfect. Check if the desired element is within an [**iframe**](https://stackoverflow.com/a/53276478/7429447) or within a [**shadowRoot**](https://stackoverflow.com/a/73242476/7429447) – undetected Selenium Feb 09 '23 at 21:59