如何从

时间:2015-06-08 14:17:13

标签: java string webdriver testng

我正在为一些网站创建一个自动测试,我正在使用WebDriver,TestNG和用Java编写的代码。在页面上显示类别的注册,在括号中是拍卖的数量,我需要将此数字作为变量,但我不知道,如何。

我使用以下代码:

WebElement number1_1_vse = (driver.findElement(By.linkText("Vše")));
String text_vse1_1 = number1_1_vse.getText();

但输出仅为:“Vše”没有(拍卖数量)

link to the website

screenshot -> image with the number

有人可以告诉我吗?

3 个答案:

答案 0 :(得分:2)

使用linktext,您只能找到嵌套的文本Vše。您需要找到包含文字Vše (949)的li 使用以下css选择器来标识元素

By bycss =By.cssSelector(".list.list-categories>li:first-child");
WebElement number1_1_vse = driver.findElement(bycss );
String text_vse1_1 = number1_1_vse.getText();

答案 1 :(得分:2)

WebElement parent = number1_1_vse.findElement(By.xpath(".."));
// which will give you access to <li>
List<WebElement> childs = parent.findElements(By.xpath(".//*"));
// childs.get(1) has the result.

答案 2 :(得分:0)

请尝试获取xpath值,然后尝试使用下面提到的语法进行搜索:

findelementbyxpath( “// * [@ ID =” 成形后 “] / H2”)

获取xpath值和元素:右键单击 - &gt;检查元素 - &gt;右键单击复制xpath