I have a script that goes to a page, clicks a button and then uses a MatcherAssert to check I am getting the right messaging on a gating modal.
Here's the script:
package com.lbr.testcases.lexology.critical_paths.gating.anon;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import com.lbr.utils.ScreenShotOnFailure;
import com.lbr.utils.SetupTests;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class gating_gtdt_work_area_pro_and_pro_compliance_product_tag_anon {
@Rule
public SetupTests st = new SetupTests();
@Rule
public ScreenShotOnFailure ss = new ScreenShotOnFailure(st);
@Test
public void gatinggtdtworkareaproandprocomplianceproducttaganon() {
WebDriver driver = st.getWebDriver();
// GIVEN that I am an anonymous user on the Lexology site
// WHEN I navigate to a GTDT work area page that has PRO and PRO Compliance product tags
driver.get("https://www.lexology.com/gtdt/workareas/banking-regulation");
// AND select a jurisidiction
WebDriverWait wait = new WebDriverWait (driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(.,\'Andorra\')]")));
WebElement ele = driver.findElement(By.xpath("//a[contains(.,\'Andorra\')]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
// THEN I will see the Login or subscribe gate
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//h1[contains(.,\'Log in\')]")));
MatcherAssert.assertThat(driver.findElement(By.cssSelector(".left-section > h1")).getText(), is("Log in"));
}
}
N.B: I have had to switch to a javascript click of the button otherwise I get an "org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <a>...</a> is not clickable at point (89, 875). Other element would receive the click: <div class="optanon-clearfix optanon-alert-box-bottom-padding"></div>
" error. I don't even make it to the assert step.
For whatever reason, the modal is being displayed but it is not being found. If I wait for the element, the wait fails.
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //h1[contains(.,'Log in')] (tried for 30 second(s) with 500 milliseconds interval)
I also tried just checking the element was present instead of matching the text. This just gives me an assertion error.
Button HTML:
<h2>Jurisdictions</h2>
<div class="lexcomponent-list listsize-half liststyle-lined lined gtdt-jurisdiction-list">
<ul>
<li class="">
<img class="flag" src="/images/flags/get.ashx?f=Andorra.gif">
<a href="/gtdt/tool/workareas/report/banking-regulation/chapter/andorra">Andorra</a>
<span class="right-text">
<span>
<span>
<span class="nowrap">
<a href="/contributors/1237043">Cases & Lacambra Abogados SLP</a>
</span>
</span>
</span>
</span>
</li>
Why can I not find the modal? The script executes without a problem in IDE.