0

I tried every thing, XPATH, NAME, TAG_NAME, CSS_SELECTOR but it allways returns me this error :

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='vote']/div[2]/div/form"}

Here is my code :

time.sleep(4)
form = navi.find_element(By.XPATH, "//*[@id='vote']/div[2]/div/form").click()

Here is the html code of the webpage :

<form action="https://www.serveursminecraft.org/serveur/" method="post">
                        <input type="hidden" name="id" id="id" value="2184">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                            <h4 class="modal-title" style="text-align: center;">Confirmation du vote pour Chocolia - Farm2Win - Lots IRL</h4>
                        </div>
                        <div class="modal-body">
                            <p style="font-size: 18px; text-align: center;"><span class="label label-info">Vous pouvez voter seulement 1 fois toutes les <b>24 heures</b>.</span></p>
                            <p style="font-size: 18px;">Vous êtes sur le point de voter pour Chocolia - Farm2Win - Lots IRL, êtes vous sur ?</p><br>
                                                        <div style="width: 300px; margin: 0 auto 1em auto;">
                                <div class="g-recaptcha" data-sitekey="6LegdhkUAAAAAJG95xpN69eylHs3bT4wRikdDQzH"></div>
                            </div>
                        </div>
                        <div class="modal-footer" style="text-align: center;">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
                            <input type="submit" class="btn btn-success" value="Confirmer le vote"><br><br>
                        </div>
                    </form>

I want to select this line of code :

<input type="submit" class="btn btn-success" value="Confirmer le vote">

Here is a part of my python code :

WebDriverWait(navi,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a'[src^='https://www.google.com/recaptcha/api2/anchor?']")))
WebDriverWait(navi,10).until(EC.element_to_be_clickable((By.XPATH,"//span[@id='recaptcha-anchor']"))).click()
time.sleep(4)
navi.find_element(By.XPATH, "//*[@id='vote']/div[2]/div/form").click()

Can you help me?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
AKihiK0
  • 13
  • 3
  • Check if `form` located inside `iframe` node – Curious koala Aug 03 '22 at 16:22
  • Please also post your python code. This may be a situation where you'll need Selenium Waits using a condition that the element exists and is clickable – Joe Carboni Aug 03 '22 at 16:24
  • I cannot find any `span[@id='recaptcha-anchor']` in the html above. Post the full url, or post the full HTML for that pager in question. – Barry the Platipus Aug 03 '22 at 17:38
  • i didn't post the whole html code but this line of code is working it clicks on the right button, the code stops working a the line navi.find_element(By.XPATH, "//*[@id='vote']/div[2]/div/form").click() and the error is no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='vote']/div[2]/div/form"} – AKihiK0 Aug 03 '22 at 17:43
  • The idea is: if you post the full html, or the url, we can check what elements are/aren't in the iframe, and when to get in, or out of the iframe. – Barry the Platipus Aug 03 '22 at 18:29

1 Answers1

1

While interacting with the reCAPTCHA you have switched to the <iframe>.

Next, to click on the element <input type="submit" class="btn btn-success" value="Confirmer le vote"> you have to shift Selenium's focus back to the default content (or parent_frame) using either of the following lines of code:

  • Using default_content():

    driver.switch_to.default_content()
    
  • Using parent_frame():

    driver.switch_to.parent_frame()
    

Now you can invoke the click as follows:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.btn.btn-success[value='Confirmer le vote']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='btn btn-success' and @value='Confirmer le vote']"))).click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352