Handling Dynamic Xpath

后端 未结 6 534
心在旅途
心在旅途 2021-01-06 18:49

Am automating things using Selenium. Need your help to handle Dynamic Xpath as below:

Driver.findElement(By.xpath(\"//[@id=\'INQ_2985\']/div[2]/tr/td/div/div[3

6条回答
  •  长情又很酷
    2021-01-06 19:11

    Good to use Regular expression

    driver.findElement(By.xpath("//*[contains(@id,'INQ_')]")
    

    Note: If you have single ID with name starts from INQ_ then you can take action on the element . If a bunch of ID then you can extract as a List and then match with the specific text of the element ( element.getText().trim() =="Linked Text" and if it matched then take action. You can follow other logic to traverse and match.

提交回复
热议问题