Reputation: 1529
In the webpage, I am trying to select the 24 off of a page number which is on there as <li class="pager__item pager__item--current">24</li>
I have a WebElement that I am selecting with driver.findElement(By.cssSelector(".pager__item--current"));
Is it possible to grab the 24 off of it using this? When I convert it to a string and print it out, I just get the .cssSelector statement in selenium.
I'm converting it to a string using:
WebElement k = driver.findElement(By.cssSelector(".pager__item--current"));
String element = k.toString();
System.out.println("" + element);
I get [[FirefoxDriver: firefox on WINDOWS (a2356021-3e80-4091-9b9d-51b9b08ec8b7)] -> css selector: .pager__item--current]
from this.
How can I extract the 24 from this?
Upvotes: 0
Views: 77
Reputation: 436
You can use getText()
method:
driver.findElement(By.cssSelector(".pager__item--current")).getText();
More details here: https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#getText()
Upvotes: 1