I have created a script in Selenium IDE that goes to this page: https://www.lexology.com/instructcounsel/find and presses the 'Example' button and then asserts that results are displayed for the search. This script runs without a problem but when I export as Java to Selenium GRID then the assert fails.
The image taken by screenshot.java shows that none of the search results have loaded:
This seems to be the case even if I add a wait for the element. I have tried also adding a js.executeScript but this hasn't helped. It looks like either the button is not being found and clicked or the asynchronous content is not loading.
Here is my exported script:
package com.lbr.testcases.lexology.experts.instruct_counsel;
import com.lbr.utils.Screenshot;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
import static org.hamcrest.CoreMatchers.is;
import org.hamcrest.MatcherAssert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.WebDriver;
public class instruct_counsel_example_anon {
private WebDriver driver;
JavascriptExecutor js;
@Before
public void setUp() throws MalformedURLException {
driver = new RemoteWebDriver(new URL("http://host.docker.internal:4444/wd/hub"), new ChromeOptions());
js = (JavascriptExecutor) driver;
new HashMap<String, Object>();
}
@After
public void tearDown() {
Screenshot.TakeScreenshot(driver);
driver.quit();
}
@Test
public void searchinstructcounselexampleanon() {
// GIVEN that I am an anonymous user on the Instruct Counsel page
driver.get("https://www.lexology.com/instructcounsel/find");
// WHEN I press the Example button
driver.findElement(By.xpath("//div[@id='do-example-search']/button")).click();
js.executeScript("window.scrollTo(0,579)");
// adding a wait for the content to be displayed
WebDriverWait wait = new WebDriverWait (driver, 60);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//h3[contains(.,\\\'3. Find your lawyer (746 matches found)\\\')]")));
// THEN some example lawyers are displayed
MatcherAssert.assertThat(driver.findElement(By.xpath("//h3[contains(.,\'David Zetoony\')]")).getText(), is("David Zetoony"));
MatcherAssert.assertThat(driver.findElement(By.xpath("//h3[contains(.,\'3. Find your lawyer (746 matches found)\')]")).getText(), is("3. Find your lawyer (746 matches found)"));
}
}