-1

Open http://www.canadapostsurvey.ca/, try to locate the "Next" navigation button click or submit it using xpath or cssselector or other method but does not work. (updates: found an alternative solution not using any find element methods but would like to hear from others)

Have tried different locator properties but none of it works, any ideas?

new  WebDriverWait(driver,5).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"nav-controls\"]/input")));
driver.findElement(By.xpath("//*[@id=\"nav-controls\"]/input")).click();`

html code:

<div id="nav-controls" class="btn-container nav-center">
<input type="submit" name="_NNext" class="mrNext" style="" value="Next" alt="Next">
</div>

Screenshot of the page:

screenshot of the page

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

0

The button is in a frame so switch to the frame("mainFrame") first then click on the button.

You can use below code to achieve the same.

System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\src\\test\\resources\\executables\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://www.canadapostsurvey.ca/");
    WebDriverWait wait = new WebDriverWait(driver, 30);
    driver.switchTo().frame("mainFrame");
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='nav-controls']/input")));
    driver.findElement(By.xpath("//*[@id='nav-controls']/input")).click();;
    driver.quit();
Dilip Meghwal
  • 632
  • 6
  • 15
0

To click() within the element with placeholder as Choose username within the url https://mail.protonmail.com/create/new?language=en, as the the desired element is within a <iframe> so you have to:

  • Induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt.
  • Induce WebDriverWait for the desired elementToBeClickable.
  • You can use either of the following Locator Strategies:
    • Using cssSelector:

      driver.get("http://www.canadapostsurvey.ca/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("frame#mainFrame")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input[value='Next']"))).click();
      
    • Using xpath:

      driver.get("http://www.canadapostsurvey.ca/");
      new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//frame[@id='mainFrame']")));
      new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='Next']"))).click();
      

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352