Reputation: 23
I'm using Selenium and Python to try and click on button on a web page as bellow:
<div id="home" class="sc-gKAaRy bGevZe"><h1 tabindex="-1" id="home_children_heading" class="sc-fujyAs fxSjMq">Vérification</h1>
<p id="home_children_body" class="sc-pNWdM hbrIBL">Veuillez résoudre l’énigme pour que nous sachions que vous n’êtes pas un robot.</p>
<a href="#" aria-describedby="descriptionVerify" id="home_children_button" class="sc-bdnxRM gonizE sc-kEqXSa duYBxC">Suivant</a>
<div id="descriptionVerify" class="Home__StyledHiddenAnnouncement-sc-lzg094-0 kfyjkn">
Défi visuel.Les utilisateurs de lecteurs d'écran doivent utiliser le défi audio ci-dessous.</div></div>
I try many solution as click by Xpath and href but no one is work, can you help me please ? here is the code i try to use it:
xPath = '//*[@id="home_children_button"]'
driver.find_element_by_xpath(xPath).click()
#With other Xpath
xPath = 'xPath = "//input[contains(@type,'submit')][contains(@id,'home_children_button')][contains(.,'Suivant')]"'
driver.find_element_by_xpath(xPath).click()
I need your help , Please!
Upvotes: 1
Views: 6145
Reputation: 11
You should write like this
xpath = browser.find_element_by_xpath('TYPE THE XPATH')
xpath.click()
Upvotes: 1
Reputation: 29362
If this id home_children_button
is unique in HTMLDOM
, then please try with below xpath :
//a[@id='home_children_button']
Code trial 1 :
time.sleep(5)
driver.find_element_by_xpath("//a[@id='home_children_button']").click()
Code trial 2 :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='home_children_button']"))).click()
Code trial 3 :
time.sleep(5)
button = driver.find_element_by_xpath("//a[@id='home_children_button']")
driver.execute_script("arguments[0].click();", button)
Code trial 4 :
time.sleep(5)
button = driver.find_element_by_xpath("//a[@id='home_children_button']")
ActionChains(driver).move_to_element(button).click().perform()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
PS : Please check in the dev tools
(Google chrome) if we have unique entry in HTML DOM
or not.
Steps to check:
Press F12 in Chrome
-> go to element
section -> do a CTRL + F
-> then paste the xpath
and see, if your desired element
is getting highlighted with 1/1
matching node.
Upvotes: 1