How do I get dynamically changing numbers in the span block ?
<div class="main-page-exchange__indicator">
<span class="main-page-exchange__rate">72,54</span></div>
</div>
Method:
@Test
public void first(){
chromeDriver.get("https://www.open.ru/");
WebElement buyRateUSD = chromeDriver.findElement(By.xpath("//span[@class='main-page-exchange__rate']"));
System.out.println("out" buyRateUSD);
}
I can't figure out how to do this. My method xpatch which returns the value:
"out[[ChromeDriver: chrome on WINDOWS (7ec6711c86cc8089e3bd06c161cdebf8)] -> xpath: //span[@class='main-page-exchange__rate']]"
How can I get dynamically changing numbers in such blocks for further comparison?
CodePudding user response:
Your code returns values of the Type WebElement
To get the text in that you need to use buyRateUSD.getText()
this should give you the text as a String and you can parse it further to use it.
CodePudding user response:
chromeDriver.get("https://www.open.ru/");
WebElement buyRateUSD = chromeDriver.findElement(By.xpath("//span[@class='main-page-exchange__rate']"));
System.out.println("out" buyRateUSD.getText());
byRaetUSD is a webelement you should call getText to get the text or you can call
buyRateUSD.getAttribute("textContent")
if element is not in the view port as getText finds inner test and will give consideration to isdisplayed . if isdisplayed is falls getText will return empty string. getAttribute("textContent") doesn't care about isDisplayed so it will return text if element is present