0

i have to automate this page using java ,and selenium. I must click on the link which has label terms and conditions it shows up a box, and then i need to navigate it down, and click on Agree button.

enter image description here

I have already tried:

        driver.click("//*[@id=\"field_terms\"]/td[2]/div/div/label[1]/a");  // Click on the link

it opens the box for me, but i stuck after it.

I have 2 problems:

  1. How to scrol down the pop up?
  2. How to click on the Agree button?

Update:

Regarding the scroll problem i used the below method which does not work:

public void scrollDown() {
        JavascriptExecutor jsx = (JavascriptExecutor)driver;
        jsx.executeScript("arguments[0].scrollTop = arguments[1];","window.scrollBy(0,450)", "");
    }
Jeff
  • 7,767
  • 28
  • 85
  • 138
  • That's not a JS alert so `Alert` won't work on it. It's HTML like the rest of the page. Post the relevant HTML for the I AGREE button and we can help. – JeffC Oct 25 '18 at 02:34
  • @JeffC sorry, but how do you identify it is not an alert, which is changed by `css`? – Jeff Oct 25 '18 at 04:20
  • You should take a look at different JS alerts. It doesn't look anything like them. One way you can confirm this is to right-click on it and see if you get a context menu and can inspect the HTML. If you can, then you know it's not a JS alert. – JeffC Oct 25 '18 at 13:01

3 Answers3

1

Try using the CSS Selector to locate the I Agree button

'div[class="ui-dialog-buttonset"]>button[btnclass="primary"]'

It worked in my system. I am not a Java person, this is the code I wrote in python for your reference

driver = Chrome()
driver.get('https://signup.insly.com/signup')

terms_and_conditions = driver.find_element_by_link_text('terms and conditions')
terms_and_conditions.click()

import time
time.sleep(2)

i_agree = driver.find_element_by_css_selector(
              'div[class="ui-dialog-buttonset"]>button[btnclass="primary"]'
          )
i_agree.click()
Satish
  • 1,976
  • 1
  • 15
  • 19
0

Let's start with the scroll: just use JavaScript...

JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("window.scrollBy(0,450)", "");

Or you can just scroll up to the element needed...

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", your_WebElement);

For the click 'I agree' use XPATH like this: "//*[text()='I AGREE']" then just preform click()

Hope this helps you!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • Thanks, i am more intersted to fix the Button problem. i have updated my question with your answer, and the new error which i got – Jeff Oct 24 '18 at 22:02
  • 1
    @KamyarParastesh I'll try again tomorrow... Hope you find a solution quick! – Moshe Slavin Oct 24 '18 at 22:06
0

Here is the code in Java [Tested & worked].

    System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/src/drivers/chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://signup.insly.com/signup");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.findElement(By.linkText("terms and conditions")).click();
    //Click the I AGREE button
    WebElement btnIagree = driver
            .findElement(By.xpath("//button[@btnclass='primary' and contains(text(),'I agree')]"));
    btnIagree.click();
    //Verify the check box for T&C is checked
    WebElement chkbxTnC=driver.findElement(By.xpath("//*[@id='agree_termsandconditions']/../span[@class='icon-check-empty icon-check']"));
    Assert.assertTrue(chkbxTnC.isDisplayed());

The problem is, as soon as you click on the T&C link, it takes few seconds to load the page and since a wait is needed before hitting the I AGREE Button. Apparently, the I AGREE Button is enabled and clickable without the need of scrolling down, so scrolling is not needed here.

Dhamo
  • 1,171
  • 3
  • 19
  • 41