python selenium click on button
For python, use the
from selenium.webdriver import ActionChains
and
ActionChains(browser).click(element).perform()
How do I make Selenium Python click on a button element?
To click on **Maybe Later**
button.
Induce WebDriverWait
() and element_to_be_clickable
() and following XPATH or CSS Selector.
XPATH:
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='modal-footer']//button[@Class='btn btn-danger x' and text()='Maybe Later']"))).click()
CSS Selector:
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.modal-footer button.btn.btn-danger.x[style='danger']"))).click()
You need to import following libraries.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Python/Selenium: Click on button element without ID attribute
There is no such method as send_mouse(Keys.LEFT)
To click() on the element with text as Accept All you can use either of the following locator strategies:
Using css_selector:
driver.find_element(By.CSS_SELECTOR, "button[tabindex='0']").click()
Using xpath:
driver.find_element(By.XPATH, "//button[text()='Accept All']").click()
xpath for click to a button - python/selenium
You probably missing a delay / wait.
After clicking the submit / login button on the login page it takes some time to make the internal page loaded.
The recommended way to do that is to use Expected Conditions explicit waits, something like this:
wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='advanced']"))).click()
To use the wait
object here you will need to import the following inports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
And to initialize the wait
object with
wait = WebDriverWait(driver, 20)
You will have to validate your locator is unique. As well as to validate the element you are trying to access is not inside iframe and not in a new window / tab etc.
How to click on Search button using Python Selenium
To click on the element Suchen you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
driver.get('https://www.jameda.de/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span[class^='SearchString']"))).click()Using XPATH:
driver.get('https://www.jameda.de/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(., 'Suchen')]"))).click()Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ECBrowser Snapshot:
Related Topics
Placing Custom Images in a Plot Window--As Custom Data Markers or to Annotate Those Markers
When Does Python Allocate New Memory for Identical Strings
Error: Command 'Gcc' Failed with Exit Status 1 While Installing Eventlet
How to Get the Input from the Tkinter Text Widget
Python's Equivalent of && (Logical-And) in an If-Statement
Compiling Numpy with Openblas Integration
Alternative to Dict Comprehension Prior to Python 2.7
Binning Data in Python with Scipy/Numpy
How to Know If a Generator Is Empty from the Start
How to Take Column-Slices of Dataframe in Pandas
Loading .Rdata Files into Python
Why am I Getting "Indentationerror: Expected an Indented Block"
Scraping: Ssl: Certificate_Verify_Failed Error for Http://En.Wikipedia.Org
Add Leading Zeros to Strings in Pandas Dataframe
How to Change the Figure Size of a Seaborn Axes or Figure Level Plot
How to Access "Static" Class Variables Within Methods in Python