Not able to extract the highlighted text alone as a string with selenium since those two are hardcoded texts without tags, kindly let me know any possiblilities.
CodePudding user response:
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);