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 >
<button type="button" data-dismiss="modal"><span aria-hidden="true">×</span><span >Close</span></button>
<h4 style="text-align: center;">Confirmation du vote pour Chocolia - Farm2Win - Lots IRL</h4>
</div>
<div >
<p style="font-size: 18px; text-align: center;"><span >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 data-sitekey="6LegdhkUAAAAAJG95xpN69eylHs3bT4wRikdDQzH"></div>
</div>
</div>
<div style="text-align: center;">
<button type="button" data-dismiss="modal">Annuler</button>
<input type="submit" value="Confirmer le vote"><br><br>
</div>
</form>
I want to select this line of code :
<input type="submit" 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?
CodePudding user response:
While interacting with the reCAPTCHA you have switched to the <iframe>
.
Next, to click on the element <input type="submit" 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()
CodePudding user response:
While interacting with the reCAPTCHA you have switched to the .
Next, to click on the element 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()