Selenium Webdriver runtime Exception: unexpected alert "Please close other open tabs of the application and re-open this activity" - selenium-webdriver

Selenium Webdriver runtime Exception: unexpected alert "Please close other open tabs of the application and re-open this activity", even though there are no other tabs open.
The Automation scripts were working fine, but recently I am getting the above exception.The Screenshot of the Alert:
I tried with different versions of chrome, selenium stand alone driver, but the issue still exist. Why is this alert coming, even though the application is not open in any of the tabs or browsers other than the one execution through online?

If this pop up is coming at some specific location every time then you can simply accept it by writing below lines :
WebDriver wb=new ChromeDriver();
wb.switchTo().alert().accept();
Else if any unexpected pop up is coming ,while initializing the driver then you can use the below code :
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
String path=new GetBasePath().getPath_XML()+dir;
prefs.put("download.default_directory", path);
options.addArguments("disable-extensions");
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.addArguments("chrome.switches","--disable-extensions");
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.driver",**path to chromedriver.exe**"));
WebDriver wb= new ChromeDriver(cap);
My personal opinion , use both.

Related

Files not found error when tried to upload files using AutoIT and Selenium

When I am trying to run the AutoIT.exe script or my Selenium script, it is throwing 'File Not found error'. Please suggest!
Selenium code snippet: ===================================
public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", "C:\\Users\\IBM_ADMIN\\Desktop\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://demo.automationtesting.in/Register.html");
driver.manage().window().maximize(); Thread.sleep(2000);
driver.findElement(By.xpath("//input[#id='imagesrc' and #type='file']")).click();
Runtime.getRuntime().exec("C:\\Users\\IBM_ADMIN\\Desktop\\Selenium practise\\SeleniumAssignment\\AutoIT\\MultipleFileUpload.exe"+" "+"C:\\Users\\IBM_ADMIN\\Desktop\\0234_005.pdf"); Thread.sleep(2000);
driver.findElement(By.xpath("//input[#id='imagesrc' and #type='file']")).click();
Runtime.getRuntime().exec("C:\\Users\\IBM_ADMIN\\Desktop\\Selenium practise\\SeleniumAssignment\\AutoIT\\MultipleFileUpload.exe"+" "+"C:\\Users\\IBM_ADMIN\\Desktop\\BRP_SujataChakraborty.pdf"); driver.quit(); }
AutoIt Code Snippet: ============================
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1",$CmdLine[0])
ControlSetText("Open","","Edit1",$CmdLine[1])
ControlSetText("Open","","Edit1",$CmdLine[2])
ControlClick("Open","","Button1")
Is brower file dialog active window? If not auto it script will enter value in window whichever is active. Do make sure file dialog active?. Do interact with brower once it is started. And one more thing if you input type is file then you can use send keys instead of auto it to enter value.

Selenium 3.0.1, gekodriver v0.11.1, firefox 49.0.2 "Unable to connect to host 127.0.0.1 on port 7055" exception

Trying to upgrade to Selenium 3.0 from Selenium 2.53. I can not put firefox in path, nor can put the gekodriver in path. I was using this in Selenium 2:
String firefoxLocation = System.getenv("ProgramFiles(X86)") + "\\Mozilla Firefox_42\\firefox.exe";
System.setProperty("webdriver.firefox.bin", firefoxLocation);
driver = new FirefoxDriver();
This worked perfectly. I upgraded to Selenium 3.0, installed firefox 49 and downloaded the latest geko. I now have this:
String firefoxLocation = System.getenv("ProgramFiles(X86)") + "\\Mozilla Firefox_49\\firefox.exe";
String gekoLocation = "..\\common\\geko\\gekodriver.exe";
System.setProperty("webdriver.firefox.bin", firefoxLocation);
System.setProperty("webdriver.firefox.marionette", gekoLocation);
driver = new FirefoxDriver();
Firefox opens to a blank window, then times out. I tried instead of setting webdriver.firefox.marionette, setting webdriver.geko.driver, but got the error that I must use "webdriver.geko.driver" (which I was using). How do I arrange it so I can specify a different firefox.exe location and a different gekodriver.exe location?
spelling wrong.
try this:
System.setProperty("webdriver.gecko.driver", gekoLocation);
use gecko instead of geko

Error when trying to login using selenium webdriver in IE11

I am getting the below error when i try to login and select a drop down in login page using selenium webdriver in IE11.
[{
DesiredCapabilities capabilities=DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("webdriver.ie.driver", "C://Users//chetana.inamdar//Desktop//selenium//IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(capabilities);
driver.navigate().to("url");
driver.findElement(By.id("ctl00_plhContent_txtUserName")).sendKeys("username");
driver.findElement(By.id("ctl00_plhContent_txtPassword")).sendKeys("Password");
driver.findElement(By.id("ctl00_plhContent_btnLogin")).click();
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
//Select dropdown=new Select(driver.findElement(By.xpath(".//*[#name='ctl00$plhContent$Tabs$pnltabPermanentArea$ddlIDSearch']")));
Select dropdown=new Select(driver.findElement(By.name("ctl00$plhContent$Tabs$pnltabPermanentArea$ddlIDSearch")));
dropdown.selectByValue("CS Number");
System.out.println("the output of selected is"+driver.findElement(By.id("ctl00_plhContent_Tabs_pnltabPermanentArea_ddlIDSearch")).isSelected());
driver.findElement(By.id("ctl00_plhContent_Tabs_pnltabPermanentArea_txtIDSearch")).sendKeys("1234");
}]
Error:

Change Browser Capabilities through Robot Framework

I do not have privileges to change IE settings locally. I wrote a Java Code to change the capabilities of IEDriver using :
DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
caps.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
I want to do the same thing while using the selenium webdriver in Robot Framework. I want to do something like this. But I do not know the right way to do it.
*** Keywords ***
Test Browser
${options}= Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.INTERNETEXPLORER sys,selenium.webdriver
Call Method ${options} add_argument INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS:True
Create WebDriver Internet Explorer ie_options=${options}
Open Browser To Login Page
Open Browser ${LOGIN URL} ${BROWSER}
Maximize Browser Window
Set Selenium Speed ${DELAY}
Login Page Should Be Open
Thanks a lot!
In the Selenium documentation for DesiredCapabilities, the configurable properties are listed. The required property is ignoreProtectedModeSettings which must be set to True
${dc} Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.INTERNETEXPLORER sys, selenium.webdriver
Set To Dictionary ${dc} ignoreProtectedModeSettings ${True}
Open Browser www.google.com ie desired_capabilitie=${dc}
${s2l}= Get Library Instance Selenium2Library
Log Dictionary ${s2l._current_browser().capabilities} # actual capabilities
For anyone that came here looking for a solution to this problem within Robot Framewor:
Set Chrome Desired Capabilities
[Documentation] Create the desired capabilities object with which to instantiate the Chrome browser.
${dc} Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.CHROME sys, selenium.webdriver
${experimental_options} Create Dictionary useAutomationExtension ${False}
Set To Dictionary ${dc} chromeOptions ${experimental_options}
Set Global Variable ${DESIRED_CAPABILITIES} ${dc}
As Pavol Travnik mentioned, David's answer no longer works. At some point the ignoreProtectedModeSettings key got placed inside the se:ieOptions dictionary within the capabilities dictionary. Here is code that will work with newer versions of the IEDriverServer:
${ie_dc} = Evaluate
... sys.modules['selenium.webdriver'].DesiredCapabilities.INTERNETEXPLORER
... sys, selenium.webdriver
${ieOptions} = Create Dictionary ignoreProtectedModeSettings=${True}
Set To Dictionary ${ie_dc} se:ieOptions ${ieOptions}
Open Browser ${url} ie desired_capabilities=${ie_dc}
You can see this if you debug Selenium's Python library, specifically webdriver/remote/webdriver.py and look at the response in start_session.

Webdriver exception: "chrome not reachable"

I am running selenium test cases in a ubuntu server which basically runs testcases in both firefox and chrome.
Firefox launches and test cases run successfully but chrome throws exception:
*****below is the snippet of the stacktrace:*****
Starting ChromeDriver (v2.8.240825) on port 21549
PAC support disabled because there is no system implementation
Test IntegrationTest.AdminUserelementscheck failed:
org.openqa.selenium.WebDriverException: chrome not reachable
(Driver info: chromedriver=2.8.240825,platform=Linux 2.6.32-431.el6.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
[error] Command duration or timeout: 20.83 seconds
Hi Below is the small snippet of my code :
public class IntegrationTest {
private static final String configFile="test.properties";
private final String FIREFOX="firefox";
private final String CHROME="chrome";
private final String PHANTOMJS="phantomjs";
private final String BROWSERNAME="browser";
private static Properties props = new Properties();
public WebDriver webDriver;
private static Configuration additionalConfigurations;
#BeforeClass
public static void setUp() throws IOException, SQLException{
props.load(IntegrationTest.class.getResourceAsStream("/" + configFile));
}
#test
public void AdminUserelementscheck() throws SQLException, IOException {
String[] browsers = props.getProperty(BROWSERNAME).split(",");
System.out.println("Number of browsers specified in conf:"+props.getProperty(BROWSERNAME));
for(String browser:browsers){
System.out.println("Browser currently processing:"+browser);
if(browser.equalsIgnoreCase(FIREFOX))
webDriver = new FirefoxDriver();
else if(browser.equalsIgnoreCase(CHROME))
webDriver = new ChromeDriver();
else
webDriver = new PhantomJSDriver();
running(testServer(3333,fakeApplication()),webDriver, new Callback<TestBrowser>() {
********* LOGIN AND ASSERTION STATMENTS*******************
browser.quit()
}
});
}
This would be because Chrome is also making use of unix containers in order to run. If you want this to run within docker, pass the docker run command
--privileged
Otherwise you can start Chrome with
--no-sandbox
I have encoutered similar problem. I am running my Selenium tests locally and "webdriver exception chrome not reachable" error suddenly showed up.
The problem was that I already had too much tabs in my regular chrome browser. After getting frustrated I have closed few tabs and suddenly it worked. I am not sure if there is a certain limit of tabs, but if somebody encounters same problem, give it a try.
Your chrome driver seems to be old. Try downloading latest as of date from below and report back if you get any new errors.
http://chromedriver.storage.googleapis.com/index.html?path=2.14/
Also ensure that PATH environment variable has the path to chromedriver.

Resources