I have been trying to use selenium python to click the Element1 or Element2 button in enter image description here
with this code :
element3=driver.find_elements_by_id("span.jump_1").click
element3=driver.find_element_by_css_selector("#jump_1 > button").click
I have tried several selectors
, xpath
..nothing seems working for me.
CodePudding user response:
There are 4 ways to click in Selenium.
I will use this xpath
//h3[@id='Element_1']
Code trial 1 :
time.sleep(5)
driver.find_element_by_xpath("//h3[@id='Element_1']").click()
Code trial 2 :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h3[@id='Element_1']"))).click()
Code trial 3 :
time.sleep(5)
button = driver.find_element_by_xpath("//h3[@id='Element_1']")
driver.execute_script("arguments[0].click();", button)
Code trial 4 :
time.sleep(5)
button = driver.find_element_by_xpath("//h3[@id='Element_1']")
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
Also if the id
is unique
, I would advise you to use id
instead of xpath
.
Also, I do not see Element 2 in HTML that you've shared.