1

I write same code for firefox driver its working fine there but its not working in chrome driver.

driver.get("https://the-internet.herokuapp.com");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id=\"content\"]/ul/li[3]/a")).click();
Thread.sleep(5000);
Alert alert = driver.switchTo().alert();
Thread.sleep(100);
alert.dismiss();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Pradnya Bolli
  • 1,915
  • 1
  • 19
  • 37
  • @DebanjanB it is not authentication issue actually alert is not finding. – Pradnya Bolli Apr 15 '19 at 04:51
  • On this [website](https://the-internet.herokuapp.com/) the locator `//*[@id=\"content\"]/ul/li[3]/a` doesn't identifies any element through `chrome-dev-tools` and the nearest locator is `//*[@id='content']/ul/li[3]/a` which identifies the element with text as **Basic Auth (user and pass: admin)**. Hence I have marked as duplicate. Let me know if I am wrong so I can _ReOpen_ the discussion. – undetected Selenium Apr 15 '19 at 05:03
  • @DebanjanB But it click on basic auth button it gives error when control goes to alert , it showing this error 'chrome not reachable' – Pradnya Bolli Apr 15 '19 at 07:19
  • You can't test **Basic Authentication** in that fashion. Can you please have a look at the duplicate target if that solves your issue? – undetected Selenium Apr 15 '19 at 09:01
  • yes that working but I just want to test like above..because same code work in firefox but its not working in chrome. – Pradnya Bolli Apr 15 '19 at 09:10

1 Answers1

0

In chrome, alert blocks the event loop. You can work around that with:

driver.executeScript("window.alert = () => null");
pguardiario
  • 53,827
  • 19
  • 119
  • 159