Search code examples
javaseleniumselenium-webdriverextractgettext

How to extract WebElements using linkText from fields and click on it


I would like to catch a text within the field and be able to click on that element. It extracts all the elements' texts into log when I use the following:

 String text;
 text = HomePageFields.TableOneColumn(driver).getText();
System.out.println("Table One Column contains following:\n" + text);

The TableOneColumn xpath is on different class:

public static WebElement TableOneColumn(WebDriver driver) throws IOException {
element = driver.findElement(By.xpath("//div[contains(@eventproxy,'isc_QMetricsView_0')]/div[1]/div[1]/div[1]/div[1]/div[1]/div[contains(@style,'position')]/div"));
    return element;

I tried to use:

HomePageFields.TableOneColumn(driver).findElement(By.linkText("RFI Overview")).click();

But it gives an error saying won't find the element.

Here is the html link to that particular text. But other text contain in the same tag but different locations within that main tag.

HTML path


Solution

  • driver.findElement(By.xpath("//td[.='RFI Overview']")).click();
    

    I'd suggest using the div with id isc_3BL as well, but I am not certain that is a static id. If it is, you could definitely use it to isolate from any other outside table containing the same exact td with text "RFI Overview"