how to get a text string from

139 views Asked by At

I am creating an automatic test for some webs and I'm using WebDriver, TestNG and code that is written in Java. On the page is shown register of categories, in parentheses is number of auctions and i need to get this number as variable, but i don't know, how.

I use the following code:

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

but output is only: "Vše" without (number of auctions)

link to the website

screenshot -> image with the number

can anyone advise me please?

3

There are 3 answers

3
Saifur On BEST ANSWER

With linktext you are finding the nested a which text is Vše only. You need to find the li containing the text Vše (949) Use the following css selector to identify the element

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
Dheerendra Kulkarni On
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.
0
The N.. On

Please try to get the xpath value and then try to search it with below mentioned syntax :

findelementbyxpath("//*[@id="post-form"]/h2")

To get xpath value of and element : right click --> inspect element --> right click copy xpath