Verify Element Existence Selenium
I know that this question has been asked in some iteration before. But I can't figure out how to do this even after looking at the API. I want to scrape data over the web and I ha
Solution 1:
Your first code snippet should raise NoSuchElementException
if the element is missing. If it does not do that, then it is unclear from the information in your question why that's the case. (Or maybe you expect it to not find an element but it does find one?)
The 2nd snippet cannot work because the find_element_...
methods return WebElement
objects, not lists of objects. You'd have to do:
iflen(browser.find_elements_by_xpath('//path')) == 0:
print ('failure')
Note the plural find_elements_...
The functions to find elements that are in the plural return lists, and if they don't find anything the list is of length zero.
By the way, the size()
method on WebElement
objects returns the rendered size of the element, that is, its height and width on the page.
Post a Comment for "Verify Element Existence Selenium"