Click On Element That Has 'x-onclick' with Python Selenium


I am trying to use selenium to click on an element with x-onclick property not onclick. Screenshot of it

I am using this element’s xPath to click on it. These are the methods I have tried:

driver.execute_script("arguments[0].click();", element)

but these don’t work. I would love if someone can tell me a solution.


When you tried this

driver.execute_script("arguments[0].click();", element)

element is a web element. I do not know if you have defined it or not. If not defined then you must have got compile time error.

Anyway this looks to me an angular based application. So I would try with below code trials :

There are 4 ways to click in Selenium.

I will use this xpath

//a[@id='generater' and @x-onclick]

Code trial 1 :

driver.find_element_by_xpath("//a[@id='generater' and @x-onclick]").click()

Code trial 2 :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='generater' and @x-onclick]"))).click()

Code trial 3 :

button = driver.find_element_by_xpath("//a[@id='generater' and @x-onclick]")
driver.execute_script("arguments[0].click();", button)

Code trial 4 :

button = driver.find_element_by_xpath("//a[@id='generater' and @x-onclick]")

Imports :

from import WebDriverWait
from import By
from import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

Answered By – cruisepandey

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published