I need to use Selenium to start up Edge and allow sites to be opened in IE mode (with Selenium).
I did do settings -> default browser -> and selected Allow and restarted.
Problem is, Edge starts up fresh every time, so the setting is no longer there.
There should be some sort of EdgeOptions or ExtraCapabilities to set at startup to make this happen
(similar to this which sets the unexpected alert handling:
capabilities.setCapability("unexpectedAlertBehaviour", "ignore");
Google search did not really find anything. It found the Capabilties class, etc, but not what the individual values you can actually set. Has anyone done this and can help me?
From your description, I understand that you want to open a site in the IE mode using Edge Selenium automation code. Correct me if I misunderstand anything.
You could try the sample JAVA code below.
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
public class IEDriverSample {
public static void main(String[] args) {
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
driver.get("http://www.bing.com");
WebElement elem = driver.findElement(By.id("sb_form_q"));
elem.sendKeys("WebDriver", Keys.RETURN);
driver.close();
}
}
Reference:
Use Internet Explorer Driver to automate IE mode in Microsoft Edge
Let me know if you have questions.
Related
I'm launch Microsoft Edge in IE mode using Selenium Java.
Can someone help me with the required configuration settings?
To launch Microsoft Edge browser in IE mode and navigate to a website e.g. http://www.bing.com you can use the following configuration and settings:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
public class IEDriverSample {
public static void main(String[] args) {
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.attachToEdgeChrome();
ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
WebDriver driver = new InternetExplorerDriver(ieOptions);
driver.get("http://www.bing.com");
}
}
I'm executing the automation script, in which I am facing loading bar for infinite time on the specific web page.
I have confirmed that issue is not from script side because earlier same scripts are executing fine.
I have applied the solutions as below.
Executing the script in other browsers
Increase wait time
Updated Chrome browser/chromedriver.exe
Currently I'm using below tools/version
Chrome Version: 89.0.4389.82
Chrome driver[Version:ChromeDriver89.0.4389.23]
Java [version: 11]
Selenium WebDriver
Can anyone please provide me the solutions?
Thanks in advance
Try changing the page load strategy to "eager":
This will make Selenium WebDriver to wait until the initial HTML document has been completely loaded and parsed, and discards loading of stylesheets, images and subframes.
When set to eager, Selenium WebDriver waits until DOMContentLoaded event fire is returned.
Example usage:
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
public class pageLoadStrategy {
public static void main(String[] args) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setPageLoadStrategy(PageLoadStrategy.EAGER);
WebDriver driver = new ChromeDriver(chromeOptions);
try {
// Navigate to Url
driver.get("https://google.com");
} finally {
driver.quit();
}
}
}
I would like to execute Firefox's screenshot --fullpage command from inside a Selenium java script.
The command is documented in Take a full page screenshot with Firefox
Is it possible?
You can just take a screenshot from within your Java code. From this answer: https://stackoverflow.com/a/3423347/8020699
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
This guy suggests using a library called aShot to take full page screenshots. Here's the link to the aShot jar. Here's the code he gives:
import java.io.File;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
public class FullPageScreenshot {
public static void main(String args[]) throws Exception{
//Modify the path of the GeckoDriver in the below step based on your local system path
System.setProperty("webdriver.gecko.driver","D://Selenium Environment//Drivers//geckodriver.exe");
// Instantiation of driver object. To launch Firefox browser
WebDriver driver = new FirefoxDriver();
// To oepn URL "http://softwaretestingmaterial.com"
driver.get("http://www.softwaretestingmaterial.com");
Thread.sleep(2000);
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
}
}
I am Not able to close the Internet Explorer via selenium script, I tried every Solution to Kill the IEDriver task and Iexplorer.exe.
I also Tried solution: Internet Explorer 11 does not close after Selenium Test 2 but it still not working for me.
I am Using below,
Selenium 3.4,
IE: 11.1358.14393.0,
InternetExplorerServerDriver: 3.4.0
Below is my code.
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Tc03_IEDriver_First_use {
public static void main(String[] args) throws Exception {
//Set IEDriver Properties
System.setProperty("webdriver.ie.driver", "D:\\Rohit Bhatkar\\Selenium Jars\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
//Set desired Capabilities of IE. these statements removes an zoomsetting error.
//You Can set Zoom mannually as, Go To View Menu on IE > Click On Zoom > Select 100%
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
//Create IEDriver obj, Open Browser, Open URL, Close the Browser
WebDriver obj1= new InternetExplorerDriver(caps);
obj1.manage().window().maximize();
obj1.get("https://www.google.com");
obj1.quit(); //IE not Closing. Steel need to do some work to close the browser
}
}
I would try to first obj1.close() to close the browser window. Then I would use obj1.quit() to quit the webdriver which would close it's terminal window in Windows.
Your code seems to work fine. I tested it and the IE browser closed at the end.
Try obj1.close(); instead of obj1.quit();
Here is the Answer to your Question:
Try these settings for IE 11:
Note: You have to set Zoom Level to 100% for IE to work properly.
System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("platform", "WIN8");
cap.setCapability("version", "11");
cap.setCapability("browserName", "internet explorer");
cap.setCapability("ignoreProtectedModeSettings",1);
cap.setCapability("nativeEvents","false");
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability("requireWindowFocus","true");
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(cap);
driver.manage().window().maximize();
driver.get("https://google.co.in");
System.out.println(driver.getTitle());
driver.quit();
Let me know if this Answers your Question.
Hi I am learning selenium grid for the first time.I am unable to understand why Desired capabilities class is used to set browser name and platform details in a remote machine.
please let me know if there is any proper documentation on it apart from google-wiki page
Thanks
prathima
Not all remote machines (or sessions) support the features requested by a user. E.g. user may want to use Chrome on Windows but some machines are only running Firefox on Linux.
The desiredCapabilities is used to describe the features of a session requested by user. You can refer to this link and this link for more info.
- when user send request to remote machine to run a particular test on
a particular browser on a particular platform.
- It doesn't mean that all the remote machine will support all the
features requested by user such as (Particular browser on a
particular machine).
**Example:**
- If user request to execute a testcase on internet explorer on Linux
platform. It doesn't mean that always Linux machine has internet
explorer it would have firefox not internet Explorer(Because it is
open source).
- Linux machine doesn't support the features requested by a User. so
that, that point of time we will use DesiredCapabilites class to set
the platform , Browser Name and version of browser of Remote Machine
to execute the Test.
Example:
package grid;
import static org.junit.Assert.*;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class SimpleGridTest
{
WebDriver driver;
String baseUrl , nodeUrl;
#Before
public void setUp() throws Exception
{
WebDriver driver;
String baseUrl , nodeUrl;
baseUrl = "https://www.facebook.com";
nodeUrl = "http://192.168.10.21:5568/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.WIN8_1);
driver = new RemoteWebDriver(new URL(nodeUrl),capability);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.MINUTES);
}
#Test
public void test() throws InterruptedException
{
driver.manage().window().maximize();
driver.get("https://www.google.co.in");
driver.findElement(By.linkText("Gmail")).click();
driver.findElement(By.id("Email")).sendKeys("abc#gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("1234");
driver.findElement(By.id("signIn")).click();
}
#After
public void tearDown() throws Exception
{
driver.quit();
}
}