Python Selenium Click On Button Without Id And Name
I have one button, and I want to click on this button , I do login_form = driver.find_element_by_xpath('/html/body/div/h1/div[1]').click(); my code : driver = webdriver.Firefox(
Solution 1:
The button is in <a>
tag, not <div>
tag. You also have only one <div>
so div[1]
is invalid. You can search by the text
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
button = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, '//a[contains(., "Download bounding boxes")]')))
button.click();
Or by class since you have only one button so class btn
should be unique.
driver.find_element_by_class_name('btn').click(); # or 'btn-success' or 'btn-sm'
By the way, click()
doesn't return anything, you can't assign it to login_form
.
Solution 2:
The button is under an <a>
tag so we write code for Xpath:
driver.find_element_by_xpath("//a[. = 'Download bounding boxes']").click()
so it finds the text is "Download bounding boxes" on the website and clicks on it.
In the code above //
a is written because the button was inside the <a>
tag we can write //span
,//div
as well if the code was under a span
or div
tag.
Post a Comment for "Python Selenium Click On Button Without Id And Name"