Home > Software engineering >  How to click on a webpage element with Python
How to click on a webpage element with Python

Time:01-04

Imgur Web Element

I want to write a line of code that clicks on the ellipsis on the webpage. I've attached the element description.

I can't share the webpage as it is password protected

Here's what I tried:

element = driver.find_element_by_css_selector('.fas.fa-ellipsis-v') element.click()

I am expecting the ellipsis to pop open but i get the following error:

Message: no such element: Unable to locate element: {"method":"css selector","selector":".fas.fa-ellipsis-v"}

CodePudding user response:

First of all, please, do not use images when your want a code review or help, it is more easier to help with raw code.

In that case:

Message: no such element: Unable to locate element: {"method":"css selector","selector":".fas.fa-ellipsis-v"}

Try to use this code below instead of driver.find_element_by_css_selector([...]) :

WebDriverWait(your_driver, your_timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, your_locator)))

or

WebDriverWait(your_driver, your_timeout).until(EC.visibility_of_element_located((By.CSS_SELECTOR, your_locator)))

After the WaitDriverWait, use your find and click code.

If you need more help locating elements by, try look the Selenium Docs.

CodePudding user response:

It worked by using the following line:

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