selenium click on anchor tag inside table td

后端 未结 2 1792
梦如初夏
梦如初夏 2021-01-23 14:48

i have my html code looks like this:

2条回答
  •  星月不相逢
    2021-01-23 15:15

    Small error in your code, you're missing '' around the text "+linktext+":

    driver.findElement(By.xpath("/table[contains(@class,'results ib-list')]/tbody/tr/td[@class = 'name']/a[contains(text(),'"+linktext+"')]")).click();
    

    NoSuchElementException usually means the element is in a frame, or slow to load. Selenium only interacts with elements in the current frame. Any element within a child frame cannot be interacted with until you switch into that frame. You can switch by using switchTo().frame():

    driver.switchTo().frame(ARG);
    

    The arguments for frame() are

    • number from 0
    • id of the frame
    • the webelement rerference of the frame

    When done in the iframe, use the following to exit back to the top of the document:

    driver.switchTo().defaultContent();
    

提交回复
热议问题