IE Mode in Edge supported by IEDriver not able to automate - java

since internet Explore is depreciated nowadays we have switched to edge browser but like you some sites support ie browser instead of edge so I need to run ie mode in edge browser here is an example of my code:
IE Mode in Edge supported by IEDriver
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
//System.setProperty("webdriver.edge.driver", "D:\\Automation\\Jar Details\\Drivers\\edgedriver.exe");
System.setProperty("webdriver.ie.driver", "D:\\Automation\\Jar Details\\Drivers\\IEDriverServer.exe");
// System.setProperty("webdriver.ie.driver", "C:\\Users\\ofoxborn\\Desktop\\IE_Edge\\IEDriverServer.exe");
InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService();
DesiredCapabilities caps = new DesiredCapabilities();
caps.setAcceptInsecureCerts(false);
caps.setBrowserName("internet explorer");
caps.setCapability("ie.edgechromium", true);
System.out.println("caps.getBrowserName() = " + caps.getBrowserName());
System.out.println("caps browserName = " + caps.getCapability("browserName"));
caps.setCapability("ie.edgepath", "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
InternetExplorerOptions options = new InternetExplorerOptions();
options.enablePersistentHovering();
options.ignoreZoomSettings();
options.requireWindowFocus();
options.setCapability("ignoreProtectedModeSettings", true);
WebDriver driver = new InternetExplorerDriver(ieService, options.merge(caps));
driver.manage().window().maximize();
driver.get("https://github.com");
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(5000);
System.out.println("caps.getBrowserName() = " + caps.getBrowserName());
System.out.println("caps browserName = " + caps.getCapability("browserName"));
driver.quit();
}
I don't know about it but when I run this the ie got invoked and run successfully I want it to start an edge browser I am using selenium 4.0.0 jar file and my ie version 10 is there something.
i am using ie driver 4.0.0
And so i done with setting in edge brwoserThis is edge browser seeting is there any window realted seeting i am misssing please help me and Thanks in advance

Well, I tested the problem and I think it is reasonable. In the official documentation it is stated that if you need to use Edge IE mode, one of the prerequisites is to enable IE11. Just refer to this doc: Edge IE mode-Prerequisites.
And as far as I know, IEdriver will start any version of IE installed in the machine, when Edge IE mode conditions are not met, it will not lanuch Edge, but default Internet Explorer.
So you could upgrade the version of IE to 11. I think this should make it work.

Related

setExperimentalOptions for Edge browser

I was able to change the download location in Chrome but when I do it for Edge browser the method setExperimentalOptions is not present for EdgeOptions. I am using Selenium 3.141.59 Java.
String location = System.getProperty("user.dir") + "\\Downloads";
HashMap preferences = new HashMap();
preferences.put("download.default_directory", location);
EdgeOptions options = new EdgeOptions();
options.setExperimentalOption("prefs", preferences); //setExperimentalOption is not existed for Edge
System.setProperty("webdriver.edge.driver","C:\\Users\\User\\Desktop\\Selenium\\Browsers\\Edge\\msedgedriver.exe");
WebDriver driver = new EdgeDriver(options);
driver.manage().window().maximize();
driver.get("https://file-examples.com/index.php/sample-documents-download/sample-doc-download/");
driver.findElement(By.xpath("//tbody/tr[1]/td[5]/a[1]")).click();
Selenium 3.141.59 the method setExperimentalOptions is undefined, after checking the Selenium EdgeDriver library I'm not finding any specific way to change the download location.
In this case, I can suggest you use the Selenium 4.0.0-beta-4 where the the .setExperimentalOption() is been defined.

Unable to locate the elements of SmartGWT application using Selenium in IE browser

I'm testing a GWT + SMARTGWT application like Paint and I'm trying to locate the elements of this web application using Selenium Webdriver. The method which I have used to locate the elements is by the relative XPath of those elements but the problem which I am currently facing is that this method is working correctly on the browsers like Chrome, Firefox, and Edge but not on the IE browser. The version of IE on my PC is 11.1593.14393.0. In the IE browser, this relative XPath method is giving a TimeOutException. I have given the explicit wait:
wait.until(ExpectedConditions.elementToBeClickable(webelement));
The IE browser is not able to find the element. I am also getting the following exception sometimes for other elements:
Exception in thread "main" org.openqa.selenium.InvalidSelectorException: Unable to locate an element with the xpath expression //img[contains(#src,'Insert XXX'] because of the following error:
Error: Bad token: ]
Among the troubleshooting solutions to this issue, I tried enabling/disabling the protected mode in IE for all the levels but this method didn't work. Along with that, I also tried checking the box next to the option - "Allow active content to run files on My Computer" but this method also failed to work.
What should I do to fix my issue?
This is my code. Here firstly, I will click on the Insert button located on the top bar of the application and after clicking on the Insert button, a window will launch on which I will click on the Close button.
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.ie.driver", "D:\\SELENIUM\\Drivers\\iedriverserver.exe");
WebDriver driver = new InternetExplorerDriver();
Thread.sleep(3000);
driver.get(baseURL);
WebDriverWait wait = new WebDriverWait(driver, 10);
final String InsertPath = "//img[contains(#src,'Insert XXXX')]";
final String closePath="//img[contains(#src,'close')]";
WebElement Insert = driver.findElement(By.xpath(InsertPath));
wait.until(ExpectedConditions.elementToBeClickable(Insert));
Thread.sleep(2000);
Insert.click();
WebElement close = driver.findElement(By.xpath(closePath));
wait.until(ExpectedConditions.elementToBeClickable(close));
Thread.sleep(3000);
close.click();
}
}
Edit: I also used finding the element using Javascript executor in my code as follows:
WebElement Insert = driver.findElement(By.xpath(InsertPath));
Thread.sleep(2000);
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].click();", Insert);
Sadly, this method also failed to work in the IE browser.
So, I was able to locate the elements by using the latest driver of the Internet Explorer and giving the following desired capabilities in my code to the IE browser.
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability("requireWindowFocus", true);
ieCapabilities.setCapability("unexpectedAlertBehaviour", "accept");
ieCapabilities.setCapability("ignoreProtectedModeSettings", true);
ieCapabilities.setCapability("disable-popup-blocking", true);
ieCapabilities.setCapability("enablePersistentHover", true);*/
System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(ieCapabilities);

Chrome is being controlled by automated test software

I am running automated tests in Chrome with Serenity BDD (Selenium).
I had to download a new ChromeDriver, because my tests could not run -> The test would open ChromeDriver but could not "Browse as user". When I googled the issue, they said I had to update ChromeDriver.
So I updated ChromeDriver to version 2.28 and I also updated the Chrome version to Version 57.0.2987.98.
But now - EVERY TIME I run my tests this annoying text comes up:
Chrome is being controlled by automated test software
And it asks me if I want to save password. (I can't add pictures because I don't have enough "points")
In the previous version, I had managed to block these 2 things by:
public class CustomChromeDriver implements DriverSource {
#Override
public WebDriver newDriver() {
try {
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
Proxy proxy = new Proxy();
String proxyServer = String.format("AProxyIDontWantToDisplay", System.getenv("proxy.username"), System.getenv("proxy.password"));
proxy.setHttpProxy(proxyServer);
capabilities.setCapability("proxy", proxy);
ChromeOptions options = new ChromeOptions();
options.addArguments(Arrays.asList("--no-sandbox","--ignore-certificate-errors","--homepage=about:blank","--no-first-run"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
return driver;
} catch (Exception e) {
throw new Error(e);
}
}
#Override
public boolean takesScreenshots() {
return true;
}
}
I know there is this one (A link to same issue),
but there are too many answers that don't work.
Anybody that knows how to remove that?
Add this to the options you pass to the driver:
options.addArguments("disable-infobars");
Previously, passing the "disable-infobars” ChromeOption to the WebDriver prevented Chrome from displaying this notification. Recently, the "disable-infobars" option has been deprecated and no longer removes the notification. The current workaround for this is to pass in an option called "excludeSwitches" and then exclude the "enable_automation" switch.
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
WebDriver driver = new ChromeDriver(options);
"disable-info" switch is not supported anymore for the latest chromedrivers. (at least 76.0).
#Rajeev's answer works and here I write the counterpart for C#.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
chromeOptions.AddExcludedArgument("enable-automation");
Driver = new ChromeDriver(chromeOptions);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));
WebDriver driver = new ChromeDriver(options);
Use the above codes for latest Chrome drivers.
Tried many of these suggested solutions, but none of them worked. OK, my code is in C#, so there might be some differences in the WebDriver implementations for different platforms.
Anyway, the solution that I got working was using the following options for Chrome when running on .NET.
var options = new ChromeOptions();
options.AddExcludedArguments("enable-automation");
On .NET there doesn't seem to be any setExperimentalOption() method on the ChromeOptions class.
While the disable-infobars route will work, it will likely suppress the infobar in all cases (as suggested here), not just the case that the OP is referring to. This is overkill at best, and could lead to unexpected and inexplicable behavior in the future if you are not getting some important message.
I think it's better to leverage the provided enable-automation switch by disabling it in the excludeSwitches area of your config/setup while doing nothing with regards to disable-inforbars. The enable-automation switch's description:
Inform users that their browser is being controlled by an automated test.
For nightwatch.conf.js it would look something like this (and worked for me):
desiredCapabilities: {
...
chromeOptions: {
excludeSwitches: ['enable-automation'],
...
}
}
This should only do what we are after: getting rid of that specific pesky message!
Edit [2017-11-14]: This is now causing an even more annoying Disable Developer Mode Extensions alert/warning. I've tried every relevant-looking flag/switch I could find that might help, but to no avail. I've filed a bug with Chromium, so we'll see and I'll try to swing back through here if I get a resolution.
"disable-infobars" flag has been deprecated, but you can avoid this message by adding the following:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("useAutomationExtension", false);
chromeOptions.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));
WebDriver driver = new ChromeDriver(chromeOptions);
Works on 2022
remove Chrome is being controlled by automated test software in python
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.chrome.options import Options
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option("excludeSwitches", ['enable-automation']);
URL = "https://google.com/"
driver.get(URL)
May someone needs this for Capybara, Watir should be like this:
Capybara.register_driver :chrome do |app|
$driver = Capybara::Selenium::Driver.new(app, {:browser => :chrome, :args => [ "--disable-infobars" ]})
end
Protractor solution:
I arrived here searching for a Protractor solution, if useful for anyone I found, with help from the above answers; with Protractor you can add Chrome specific options to the chromeOptions object, within the capabilities object in the protractor.config file, for example to use the disable-infobars option discussed above use the following:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['disable-infobars']
}
},
To use the enable-automation also discussed above:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'excludeSwitches': ['enable-automation']
}
}
disable-infobars is preferred in my circumstances.
It works for me, with this code I am able to disable Chrome is being controlled by automated test software as well as the Save password popup`
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options)
Map<String, Object> prefs = new HashMap<String, Object>();
//To Turns off multiple download warning
prefs.put("profile.default_content_settings.popups", 0);
prefs.put( "profile.content_settings.pattern_pairs.*.multiple-automatic-downloads", 1 );
//Turns off download prompt
prefs.put("download.prompt_for_download", false);
prefs.put("credentials_enable_service", false);
//To Stop Save password propmts
prefs.put("password_manager_enabled", false);
ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches","--disable-extensions");
//To Disable any browser notifications
options.addArguments("--disable-notifications");
//To disable yellow strip info bar which prompts info messages
options.addArguments("disable-infobars");
options.setExperimentalOption("prefs", prefs);
System.setProperty("webdriver.chrome.driver", "Chromedriver path");
options.addArguments("--test-type");
driver = new ChromeDriver(options);
Log.info("Chrome browser started");
public WebDriver SetupChromeDriver(){
//Initialize Chrome Driver
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("safebrowsing.enabled", "true");
options.setExperimentalOption("prefs", prefs);
options.addArguments("--disable-notifications");
options.addArguments("--start-maximized");
options.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver", "E:/Importent Softwares/Chrome Driver/chromedriver_2.37.exe");
driver = new ChromeDriver(options);
return driver;
}
It works for me by using addArguments(array("disable-infobars"))
This is for facebook/php-webdriver
$options = new ChromeOptions();
$options->addArguments(array("disable-infobars"));
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
$this->driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities);
You may use this
options1.add_argument("--app=https://www.google.com.ph")
If anyone is using Rails 5.1+, which changed the testing structure a bit and Capybara is configured in this file now for system tests:
application_system_test_case.rb
You can add "args" in the options for driven_by like this:
driven_by :selenium, using: :chrome, screen_size: [1400, 1400], options: { args: ["--disable-infobars"] }
It took a lot of fiddling but eventually I found a combination of flags that works in 2021!
This tells Chrome to ignore all SSL errors, disables the "Chrome is being controlled by automated test software" message and starts in full screen.
Add it to the Target field of your shortcut:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --ignore-certificate-errors --test-type=webdriver --start-fullscreen

Load Chrome Profile using Selenium WebDriver using java

I'm having some troubles getting Selenium loading a chrome profile.
String pathToChrome = "driver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", pathToChrome);
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
String chromeProfile = "C:\\Users\\Tiuz\\AppData\\Local\\Google\\Chrome\\User Data\\Default";
ArrayList<String> switches = new ArrayList<String>();
switches.add("--user-data-dir=" + chromeProfile);
capabilities.setCapability("chrome.switches", switches);
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http://www.google.com");
It starts great and works perfect, but I want to get the default profile loaded because I want to test it with some Extensions enabled and some preferences tested.
Does anybody has an idea why this code isn't working?
I've tested it with Selenium 2.29.1 and 2.28.0 with chromedriver 26.0.1383.0 on windows 7 x64.
This is an old question, but I was still having a problem getting it to work so I did some more research to understand what was happening. The answer from #PrashanthSams is correct, but I was incorrectly adding \Default to the end of the profile path
I found that Chrome appends \Default to the profile path specified in the user-data-dir. So if your profile path is specified as:
user-data-dir=C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default\
it will append \Default and you will end up at:
C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default\Default
which is not the same as the profile that you would get if you opened chrome under that user profile normally.
You can also verify your settings if you open a command prompt, navigate to the chrome executable directory, and run chrome with the options specified similar to this:
chrome.exe --user-data-dir="C:\Users\user_name\AppData\Local\Google\Chrome\User Data"
Finally, you can go to a new tab in Chrome and browse to chrome://version/ you will see the actual profile that is being used. It will be listed like:
Profile Path C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default
These combinations did trick for me :)
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
You should try this
op.addArgument("--user-data-dir=C:/Users/username/AppData/Local/Google/Chrome/User Data/");
op.addArgument("--profile-directory=Profile 2");
Path where Chrome stores the profiles on Linux.
String chromeProfilePath = "/home/(user)/.config/google-chrome/Profile3/";
Creating ChromeOptions object, desabling the extensions and adding the profile I want to use by ".addArguments".
ChromeOptions chromeProfile = new ChromeOptions();
chromeProfile.addArguments("chrome.switches", "--disable-extensions");
chromeProfile.addArguments("user-data-dir=" + chromeProfilePath);
As said above by JasonG, after this point Google-Chrome will append \Default to the String you've provided.
There is a "/Default" folder inside "/Profile3" directory, so what I did was...
I copied the content of "/Profile3" to the "/Default" folder.
Set the Browser System Properties and Path as you usually do, call the constructor that receives a ChromeOption and it will work fine.
WebDriver driver = new ChromeDriver(chromeProfile);
I copied default profile to any other folder and then I do connect to this copy
ChromeOptions options = new ChromeOptions();
options.AddArgument("--user-data-dir=C:\\AnyFolder");
driver = new ChromeDriver(options);
So it uses default profile
I tried in windows and following code works for me:
String userProfile= "C:\\Users\\user_name\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\";
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir="+userProfile);
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
How to know whether it is working ?
One way to know is to run the program twice without killing previous instance of the chrome. If the profile is valid, you'll see the second instance "as a new tab" in the first browser window. If it is not working, you get the second instance "as a new browser window".
According to the ChromeDriver wiki, this is a known issue and is currently not possible.
https://code.google.com/p/selenium/wiki/ChromeDriver
None of these above solutions works for me. And after several hours tirelessly research and trying, I already found out this solution
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-maximized");
//chrome://version/
chromeOptions.addArguments("--user-data-dir=/home/{username}/.config/google-chrome");
//load default profile
chromeOptions.addArguments("--profile-directory=Default");

Selenium web driver | java | unable to switch between firefox browser windows

Using Selenium Webdriver 2. java.
I would like to switch back in forth between two firefox browser windows. When I do I get: org.openqa.selenium.NoSuchWindoException: Unable to loacate window"{accb1cc2-74c9-3b4e-8f71-c0b184a037c4}"; duration or timeout:
Here is the java:
driver = new FirefoxDriver();
driver.get("http://mail.google.com");
String firstWindowHandle = driver.getWindowHandle();
System.out.println("handle of first window ="+firstWindowHandle);
Thread.sleep(1000);
driver = new FirefoxDriver();
driver.get("http://www.google.com");
// Get names of currently open windows
String secondWindowHandle = driver.getWindowHandle();
System.out.println("handle of first window ="+secondWindowHandle);
Thread.sleep(1000);
// It fails right here!
driver.switchTo().window(firstWindowHandle );
driver.get("http://www.lifehacker.com");
It prints the following to the console:
- handle of first window = {accb1cc2-74c9-3b4e-8f71-c0b184a037c4}
- handle of the second window = {f5256619-a36e-a441-9979-937da0abacd1}
All help is appreciated.
Unfortunately, you cannot switch between windows the way you are currently trying to do it - WebDriver lost the first window as soon as you instantiated a new instance.
You could try opening the second window via javascript and then switching back and forth from it:
window.open('http://www.bing.com','Bing','modal=yes,alwaysRaised=yes')
This is a bit of a hack, and could have the following problems:
Popup blockers may prevent the action
The browser must have javascript enabled
Future browser versions may break the hack
Complaining and murmuring from peers (and perhaps rightly so) because even though it might work, it's still a hack ;)
Some final thoughts:
Is there any particular reason it has to be the same driver instance?
If not, just switch between two driver instances:
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://mail.google.com");
FirefoxDriver driver2 = new FirefoxDriver();
driver2.get("http://www.google.com");
Swtiching between 2 active Windows:
FirefoxDriver wd=new FirefoxDriver();
wd.get("https://irctc.co.in/");
wd.manage().timeouts().implicitlyWait(5000,TimeUnit.SECONDS);
WebElement wb=wd.findElement(By.linkText("Cabs"));
wb.click(); //Now 2 Windows are open
wd.manage().timeouts().implicitlyWait(5000,TimeUnit.SECONDS); //Wait for the complete page to load
Set<String> sid=wd.getWindowHandles(); //getWindowHandles() method returns the ids of all active Windows and its return type will be a Collection Set.
Iterator<String> it=sid.iterator(); //Using iterator we can fetch the values from Set.
String parentId=it.next();
System.out.println(parentId);
String childId=it.next();
System.out.println(childId);
wd.switchTo().window(childId); //swtiching control to child Window
wd.close(); //control returns to the parent Window.

Categories

Resources