How to find elements by multiple different xpaths



  • I have this bit of code, I am not sure why it is not working.

    String xpath1="//span[contains(text(),'I am span')]";
    String xpath2="//div[contains(text(),'I am Div')]";
    String xpath3="//input[contains(text(),'I am input')]";
    

    then I combnie all the xpaths like this.

    String majorxpath="\""+xpath1+" or "+xpath2+" or "+xpath3+"\"";
    List<Webelemnt> results=driver.findelements(By.xpath(majorxpath));
    

    This returns error, unable to locate an elemnent by majorxpath.

    Please note that, I want to evaluate xpath1, xpath2, xpath 3 together and if any of them exists, the webelemnt should return in results

    Also, note the xpaths work individually but I want to see if any of them are existing and return the webElemnt.



  • Try below xpath to identify.

    //span[contains(text(),'I am span')] | //div[contains(text(),'I am Div')] | //input[contains(text(),'I am input')]
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2