DEV Community

Jose Martin
Jose Martin

Posted on

2 1

Visibility of element in DOM (Python with Selenium)

Hello,
I am struggling to find a more efficient way to identify if an element is visible in the DOM or not.
I am creating a simple automation script with selenium and python and the best way i found is to use is self.driver.find_elements_by_xpath("xpath") with len function. it would look like this

verify_element = len(self.driver.find_elements_by_xpath(".//xpath"). If it will return the result in a list. If element exist it will return "1" and if it doesn't it will return "0"

The mentioned above works great but it has a mayor setback which is that it takes too long time for that line of code to execute.

It would be very appreciated if you guys have a better way/solution to share.

thanks in advanced.

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →