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 {
public SetupTests st = new SetupTests();
public ScreenShotOnFailure ss = new ScreenShotOnFailure(st);
  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
    // AND select a jurisidiction
    WebDriverWait wait = new WebDriverWait (driver, 30);
    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:

    <div class="lexcomponent-list listsize-half liststyle-lined lined gtdt-jurisdiction-list">
            <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 class="nowrap">
                                    <a href="/contributors/1237043">Cases &amp; Lacambra Abogados SLP</a>

Why can I not find the modal? The script executes without a problem in IDE.

  • please add the html of that button you are waiting for tobe clicked
    – PDHide
    Jun 17 at 13:39
  • @PDHide I have added it to the main question. Is it enough? Jun 17 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.