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

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


Actually By.linkText() locates <a> elements by the exact text it displays while desire text is not inside any <a> tag. That's why you're in trouble.

You should try using By.xpath() with this text as below :-

WebElement el = driver.findElement(By.xpath(".//div[descendant::td[text() = 'RFI Overview']]"));System.out.println("Table One Column contains following:\n" + el.getText());el.click();

Or

WebElement el = driver.findElement(By.xpath(".//div[normalize-space(.) = 'RFI Overview']"));System.out.println("Table One Column contains following:\n" + el.getText());el.click();

Or As I'm seeing in provided screenshot desire <div> has id attribute which value looks like unique. If this attribute value is fixed for this element, you can also try using By.id() as :-

WebElement el = driver.findElement(By.id("isc_3BL"));System.out.println("Table One Column contains following:\n" + el.getText());el.click();


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"