How can I get the text of an element using the getText() method? How can I fetch text from a webpage that might be present in any of the web-element?
1 Like
Please share the application and the element from which you want to get the text. or at least div
In general, Selenium has getText() method
// option 1
String text = driver.findElement(by).getText();
// option 2
public String getTextByJS(WebElement element){
String text="";
JavascriptExecutor executor = (JavascriptExecutor) driver;
logger.info("Clicking Locator by using JScript "+ element);
text=(String) executor.executeScript(βreturn arguments[0].innerHTML;β, element);
return text;
}
Are you talking about the contains(text() , ) XPATH locator?
my python code like so
driver.find_element_by(XPATH, β//b[contains(text(), βConclusionβ)]β)
to return any bold element that contains the word Conclusion