-1

Unable to click a button . Firefox version 56.0

WebDriver wd = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) wd;
wd.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html");

wd.findElement(By.xpath("//input[@id='sum1']")).sendKeys("5");
wd.findElement(By.xpath("//input[@id='sum2']")).sendKeys("10");
WebElement e1 = wd.findElement(By.xpath("//button[@class='btn btn-  
default']"));
js.executeScript("arguments[0].scrollIntoView();",e1 );
Thread.sleep(10000);
e1.click();

I want to click 'Get Total' button but "Canceled page load listener because no navigation has been detected" message is showing.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • FWIW: FF 56 is 2+ years old. You should update FF and geckodriver and see if the issue persists. – orde Sep 16 '19 at 16:20

2 Answers2

0

Induce WebDriverWait and elementToBeClickable() and following xpath

wd.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html"); 
WebDriverWait wait = new WebDriverWait(wd, 10); 
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='sum1']"))).sendKeys("5");
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='sum2']"))).sendKeys("10");
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn-default'][text()='Get Total']"))).click();
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

To click() on the element with text as Get Total you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    WebDriver wd = new FirefoxDriver();
    wd.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html");
    new WebDriverWait(wd, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control#sum1"))).sendKeys("5");
    wd.findElement(By.cssSelector("input.form-control#sum2")).sendKeys("5");
    wd.findElement(By.cssSelector("button.btn.btn-default[onclick^='return total']")).click();
    
  • xpath:

    WebDriver wd = new FirefoxDriver();
    wd.get("https://www.seleniumeasy.com/test/basic-first-form-demo.html");
    new WebDriverWait(wd, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='form-control' and @id='sum1']"))).sendKeys("5");
    wd.findElement(By.xpath("//input[@class='form-control' and @id='sum2']")).sendKeys("5");
    wd.findElement(By.xpath("//button[@class='btn btn-default' and text()='Get Total']")).click();
    
  • Browser Snapshot:

seleniumeasy

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