My question is how can I perform click on element to get data from server response?
Algorithm:
1) Click on div element
<div class="contact-button link-phone {'path':'phone', 'id':'z8rpg', 'id_raw': '519183738'} atClickTracking contact-a" data-rel="phone">
<i data-icon="phone"></i>
<strong class="xx-large"> TEXT1 </strong>
</div>
2) Sending request to server
3) Server sends response with modified text.
So I need to get that modified text(TEXT1 in code). I have done it like this :
HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME);
driver.get("https://www.olx.ua/obyavlenie/audi-a4-1998-IDzaH8c.html#c890172227;promoted");
System.out.println("Title: " + driver.getTitle());
WebElement webElement = driver.findElement
(By.xpath("//*[@id=\"contact_methods\"]/li[2]/div"));
webElement.click();
Thread.sleep(3000);
webElement = driver.findElement
(By.xpath("//*[@id=\"contact_methods\"]/li[2]/div"));
phone = webElement.getText();
UPDATE :
As I understand, after getting response from server div element is reloading, not whole page. I need to wait until div element finish reloading. Using debug mode I noticed strange thing. In this line:
phone = webElement.getText();
State of webElement: readyState_ = "loading"