'Extract Text from Website without any HTML tags with selenium
Solution 1:[1]
You can use the below xpath:
//strong[text()='Customer']/../following-sibling::div/descendant::div[starts-with(@class,'col-md-10')]
like this:
String gottenText = new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//strong[text()='Customer']/../following-sibling::div/descendant::div[@class='col-md-10']"))).getAttribute("innerText");
System.out.println(gottenText);
that shall provide the below output:
Email [email protected]
Password demouser
Update:
you can store them into String variable like below:
String gottenText = new WebDriverWait(driver, Duration.ofSeconds(20)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//strong[text()='Customer']/../following-sibling::div/descendant::div[@class='col-md-10']"))).getAttribute("innerText");
String[] arr = gottenText.split(" ");
String[] userNames = arr[1].split("\\r?\\n");
String userName = userNames[0];
String password = arr[2];
System.out.println(userName + " " + password);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

