question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Utility to check element present or not

See original GitHub issue

Meta -

OS: Any

Selenium Version: 2.53

Browser: chrome

Browser Version: 50.0.2661.94 m

Expected Behavior -

It’s better to have an utility method (inside selenium api) which will allow us to check particular web element is present or not. Please let me know if there is any api available already.

Actual Behavior -

we need to get elements(instead of element) then we need to check the size of the elements, like below.

List<WebElement> elements=driver.findElements(By.className("myCSS"));
        if(elements.size()>=1){
            --do some operation
        }

Steps to reproduce -

Get an element, and check whether it exists or not.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ddavisoncommented, May 17, 2016

we have the ExpectedConditions utility class to do just this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Verifying whether an element present or visible in Selenium ...
To check the visibility of an element in a page, the method isDisplayed is used. It returns a Boolean value( true is returned...
Read more >
Test if an element is present using Selenium WebDriver
To find if a particular Element is present or not, we have to use the findElements() method instead of findElement ...
Read more >
Verifying whether an element present or visible in ... - Edureka
The isDisplayed method in Selenium verifies if a certain element is present and displayed. If the element is displayed, then the value returned ......
Read more >
assertElementPresent, verifyElementPresent - Selenium IDE
In the UI.Vision RPA IDE assertElementPresent is technically like a Click command with the click, it just checks if element is present. This...
Read more >
How to Check If an Element Exists in Selenium | Testim Blog
Verifying the existence of an element on a page is a common use case for a browser automation tool. In this post, we've...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found