java - Selenium automatically accepting alerts -


does know how disable this? or how text alerts have been automatically accepted?

this code needs work,

driver.findelement(by.xpath("//button[text() = \"edit\"]")).click();//causes page alert() alert alert = driver.switchto().alert(); alert.accept(); return alert.gettext(); 

but instead gives error

no alert present (warning: server did not provide stacktrace information) command duration or timeout: 2.14 seconds 

i using ff 20 selenium 2.32

just other day i've answered similar it's still fresh. reason code failing if alert not shown time code processed fail.

thankfully, guys selenium webdriver have wait implemented it. code simple doing this:

string alerttext = ""; webdriverwait wait = new webdriverwait(driver, 5); // wait maximum of 5 seconds, everytime wait used  driver.findelement(by.xpath("//button[text() = \"edit\"]")).click();//causes page alert()  wait.until(expectedconditions.alertispresent()); // before try switch given alert, needs present.  alert alert = driver.switchto().alert(); alerttext = alert.gettext(); alert.accept();  return alerttext; 

you can find api expectedconditions here, , if want code behind method here.

this code solves problem because can't return alert.gettext() after closing alert, store in variable you.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -