我试图找到元素,以便我可以使用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代码链接(发布图片的声誉不足):
答案 0 :(得分:0)
你可以试试这个:
WebElement element = driver.findElement(By.xpath("//text[@dominant-baseline=\"middle\"]"));
wait.until(ExpectedCondition.elementToBeClickable(element));
System.out.println(element.getText());
OR
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());
}