我编写了一个代码来查找Gmail收件箱中的邮件数量。下面的代码打印出5198的1-100。我希望输出只有5198.任何人都可以帮助如何获取文本的一部分作为输出来自webelement。?
package com.training.edureka.selenium.module4;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class numberOfMails {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver","C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe");
driver = new ChromeDriver();
Thread.sleep(20000);
driver.get("https://www.gmail.com");
driver.manage().window().maximize();
WebElement email = driver.findElement(By.cssSelector("input[type='email']"));
email.sendKeys("ukn@gmail.com");
WebElement next1 = driver.findElement(By.className("CwaK9"));
next1.click();
Thread.sleep(10000);
WebElement pwd = driver.findElement(By.cssSelector("input[type='password']"));
pwd.sendKeys("juiweji123*");
WebElement next2 = driver.findElement(By.cssSelector("span[class='RveJvd snByac']"));
next2.click();
Thread.sleep(20000);
String inbox = driver.findElement(By.id(":ya")).getText();
System.out.println(inbox);
}
}
答案 0 :(得分:1)
您可以按of
String inbox = driver.findElement(By.id(":ya")).getText();
String[] data = inbox.split("of ");
System.out.println(data[1]);