html - How to find the xpath of a header title in Selenium Webdriver with Java -
i need xpath of header title provides class , text within 'inspect element' tab.
the goal have if statement check see if title of page matches intended header can run code command selenium. reason why don't use "find web elements linktext" because actual content of header viewable in various pages. therefor, code run since text present. cannot use class since class name same every page.
i need header using both class name , text.
i have tried if(driver.findelements(by.xpath("//*[@class='classname' , contains (text(),'headertext')]")) !=null)
if header text doesn't match continue run. believe because technically class present text although different elements.
two possible points there:
driver.findelements(..)
never null. return empty collection if no matching elements found. so, usedriver.findelements(..).isempty()
handle case when nothing found- try using
contains(.,'headertext')
instead ofcontains(text(),'headertext')
if still no elements found. first option work when header text element contains child tags / formatting tags.
Comments
Post a Comment