1
votes

Using Selenium for Java, I try to automate setting of 2 elements - Merchant integration version (v5/v6), and Merchant Checkout ID (Sandbox-V7-STD-9CCBB) on the https://stage.masterpassteststore.com/configuration page.

I have already solved setting the environment (Sandbox/Production) but nothing more.

        // Setting the environment
        try {
            Select environments = new Select((new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.id("select_environment")))));

            environments.selectByVisibleText("Sandbox");

            System.out.println("Selected environment: " + environments.getFirstSelectedOption().getText());

            System.out.println("Number of selected environments: " + environments.getAllSelectedOptions().size());

            } catch ( Exception e ) {
            System.out.println("Setting the environment failed. " + e.getMessage());}

        driver.quit();
    }
}

Any help from smarter people welcome. :)

The only one suggestion from "Dmitri T" ends in the error below:

Starting ChromeDriver 75.0.3770.140 (2d9f97485c7b07dc18a74666574f19176731995c-refs/branch-heads/3770@{#1155}) on port 37781 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. Srp 23, 2019 12:57:04 ODP. org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: W3C Environment selected successfully: Sandbox Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element ... is not clickable at point (669, 464). Other element would receive the click: ... (Session info: chrome=75.0.3770.80) Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:22.379Z' System info: host: '*', ip: '10.45.1.194', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_221' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.80, chrome: {chromedriverVersion: 75.0.3770.140 (2d9f97485c7b..., userDataDir: C:\Users*\AppDat...}, goog:chromeOptions: {debuggerAddress: localhost:55213}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify} Session ID: 903a3ae8fe6f8d9e7260742bb2ffa419 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83) at App.main(App.java:36)


1
What the problem here? - frianH

1 Answers

0
votes

The application you're trying to automate heavily relies on AJAX therefore you will need to use Explicit Waits everywhere to ensure that element is present/clickable/not covered by loading spinner, etc.

Example code:

driver.get("https://stage.masterpassteststore.com/configuration");

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='v5']/parent::*"))).click(); // click v5
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//td/div[@class='loader']"))); // wait until loader hides
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@title, 'checkout identifier')]"))).click(); //click the dropdown

List<WebElement> choices = new WebDriverWait(driver, 10) //get all options
        .until(ExpectedConditions
                .presenceOfAllElementsLocatedBy(By.xpath("//div[contains(@class,'row-inner')]")));

WebElement randomChoice = choices.get(new Random().nextInt(choices.size() - 1)); // get random option
randomChoice.click();

More information: How to use Selenium to test web applications using AJAX technology