找不到元素并使用 Selenium WebDriver 获取文本
Cannot find element and get text using Selenium WebDriver
我正在尝试查找元素,以便我可以使用 selenium webdriver 获取文本并将其另存为字符串,但是我遇到了没有此类元素的异常。
JAVA:
WebDriver driver = new ChromeDriver();
driver.get("https://ld2025.wdf.sap.corp/sap/bi/launchpad/#item_type=HANALYTIC");
try{
Thread.sleep(10000);
}catch(InterruptedException e){
System.out.println("got interrupted!");
}
WebElement searchBox = driver.findElement(By.xpath("//*[@id='itemNameLbl_608963021']"));
searchBox.click();
driver.switchTo().defaultContent();
try{
Thread.sleep(15000);
}catch(InterruptedException e){
System.out.println("got interrupted!");
}
WebElement searchBox2 = driver.findElement(By.xpath("//*[@id='UIComp_1']/svg/g[3]/g/g/text"));
String number = searchBox2.getText();
System.out.println(number);
HTML 代码 link(post 图片的信誉不足):
你可以试试这个:
WebElement element = driver.findElement(By.xpath("//text[@dominant-baseline=\"middle\"]"));
wait.until(ExpectedCondition.elementToBeClickable(element));
System.out.println(element.getText());
或
List<WebElement> list = driver.findElements(By.tagName("text"));
for(int i=0;i<list.size();i++)
{
if(list.get(i).getAttribute("x").equals("384.5"))
System.out.println(list.get(i).getText());
}
我正在尝试查找元素,以便我可以使用 selenium webdriver 获取文本并将其另存为字符串,但是我遇到了没有此类元素的异常。
JAVA:
WebDriver driver = new ChromeDriver();
driver.get("https://ld2025.wdf.sap.corp/sap/bi/launchpad/#item_type=HANALYTIC");
try{
Thread.sleep(10000);
}catch(InterruptedException e){
System.out.println("got interrupted!");
}
WebElement searchBox = driver.findElement(By.xpath("//*[@id='itemNameLbl_608963021']"));
searchBox.click();
driver.switchTo().defaultContent();
try{
Thread.sleep(15000);
}catch(InterruptedException e){
System.out.println("got interrupted!");
}
WebElement searchBox2 = driver.findElement(By.xpath("//*[@id='UIComp_1']/svg/g[3]/g/g/text"));
String number = searchBox2.getText();
System.out.println(number);
HTML 代码 link(post 图片的信誉不足):
你可以试试这个:
WebElement element = driver.findElement(By.xpath("//text[@dominant-baseline=\"middle\"]"));
wait.until(ExpectedCondition.elementToBeClickable(element));
System.out.println(element.getText());
或
List<WebElement> list = driver.findElements(By.tagName("text"));
for(int i=0;i<list.size();i++)
{
if(list.get(i).getAttribute("x").equals("384.5"))
System.out.println(list.get(i).getText());
}