I am trying to mouse hover on an element using Action class and then trying to go to other sub element and click, but my mouse hover is pointing some where else.
These are the IE capability which are set for IE and action class code
InternetExplorerOptions options = new InternetExplorerOptions();
options.enablePersistentHovering();
options.ignoreZoomSettings();
driverinstance = new InternetExplorerDriver(options);
WebDriverWait myWaitVar = new WebDriverWait(driver, const_waithigh);
myWaitVar.until(ExpectedConditions.elementToBeClickable(By.xpath(element1)));
Actions action = new Actions(driver.get());
action.moveToElement(driver.findElement(By.xpath(element1))).click().build().perform();
Even if you ignore zoom using options.ignoreZoomSettings(); IE doesn't calculate the correct position of the element unless your application is fully maximized and zoomed at 100%.
so use the below code once you initialize the driver instance for IE.
driver.manage().window().maximize();
driver.findElement(By.tagName('html')).sendKeys(Keys.chord(Keys.CONTROL, "0"));
We are essentially maximizing the window and pressing CTRL+0 to set to the zoom to default level. See if this fixes your issue.
Issue: I'm trying to scroll in Selenium using moveByOffset(x,y), however, the cursor is not shifting focus to the provided co-ordinates -
JavascriptExecutor js = (JavascriptExecutor) driver;
//Find page height
int pageHeight = ((Number) js.executeScript("return window.innerHeight")).intValue();
//moveByOffset not working
Actions a = new Actions(driver);
a.moveByOffset(500, 300).click().build().perform();
Objective: Find the length of the page and scroll taking screenshots until the end of page is reached. (I've made a separate method for handling screenshots)
This has been discussed in thread - Selenium moveByOffset doesn't do anything, but unsure if it has been resolved. Any help would be appreciated.
I have a GIS-based application to test, I want to draw certain shapes on a canvas in Internet Explorer browser, but the control is not clicking on the web canvas element. my code is working fine in Chrome and Mozilla browsers but I need to make it work in IE also(IE11 to be precise).
My Code Is:
WebElement image = driver.findElement(By.xpath(".//*[#id='map']/div/canvas"));
Actions builder = new Actions(driver);
WebElement canvasElement = null;
org.openqa.selenium.Point point = image.getLocation();
int xcord = point.getX();
System.out.println("Element's Position from left side Is "+xcord +" pixels.");
int ycord = point.getY();
System.out.println("Element's Position from top side Is "+ycord +" pixels.");
builder.clickAndHold(canvasElement).moveByOffset(150, 100).
moveByOffset(180,100).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
builder.clickAndHold(canvasElement).moveByOffset(-100,-150).doubleClick().moveByOffset(180,200).moveByOffset(-220,-170).doubleClick().click()
.build().perform();
I'm using Soda to run Selenium Webdriver. Mostly it's working as expected but I'm trying to figure how to send the right and left cursor keys to the browser to move a jquery ui slider handle.
I tried
.typeKeys('css=a.ui-slider-handle[lr="l"]','\37')
and
.type('css=a.ui-slider-handle[lr="l"]','\37')
and
.typeKeys('\37')
and
.type('\37')
Nothing seems to move the slider. None of them error either. I'm sending a click to the handle before I do this just to be sure...
Anyone know how to do this?
Working code in Java-
WebDriver driver = new InternetExplorerDriver();
driver.get("http://jqueryui.com/demos/slider/");
//Identify WebElement
WebElement slider = driver.findElement(By.xpath("//div[#id='slider']/a"));
//Using Action Class
Actions move = new Actions(driver);
Action action = move.dragAndDropBy(slider, 30, 0).build();
action.perform();
driver.quit();
Source - https://gist.github.com/2497551
Try below, I tested this in firefox with jquery UI slider page and it worked for me.
.clickAt("//div[#id='slider']/a[1]", "")
//mouse left key down
.mouseDownAt("//div[#id='slider']/a[1]", "0,0")
//move the cursor some 200 from left
.mouseMoveAt("//div[#id='slider']", "200,0")
//Release the mouse button
.mouseUpAt("//div[#id='slider']", "");
I'm trying to run tests against IE8 but I've encountered a strange issue:
When creating the webdriver instance (driver = Selenium::WebDriver.for :ie), IE starts up and an exception is thrown by WebDriver:
"Unexpected error launching Internet Explorer. Browser zoom level was set to 0%"
IE seems to show a failure to connect to the IE Driver Server but if I refresh the browser manually, it connects just fine.
I have checked online and only two other people seem to have reported this. One possible solution was to ensure that all zones have the same "protected mode" settings, which they do.
My environment is Windows 7 and IE8 with IE Driver Server v2.25.3 and I'm using the Ruby bindings.
Any ideas?
According to the answer given by Jim Evans (one of Selenium developers) in this thread at WebDriver User Group the code below should fix your problem.
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
driver = new InternetExplorerDriver(caps);
Since the question isn't tagged with a specific language, and since JacekM's answer didn't work for me in C# (given the casing, I assume his is for Java...). I'll put the corresponding solution for C# here:
var service = InternetExplorerDriverService.CreateDefaultService(#"Path\To\Driver");
// properties on the service can be used to e.g. hide the command prompt
var options = new InternetExplorerOptions
{
IgnoreZoomLevel = true
};
var ie = new InternetExplorerDriver(service, options);
To quickly fix it adjust your browser zoom to 100%.
The most robust approach
Before you start with Internet Explorer and Selenium Webdriver Consider these two important rules.
The zoom level :Should be set to default (100%) and
The security zone settings : Should be same for all. The security settings should be set according to your organisation permissions.
How to set this?
Simply go to Internet explorer, do both the stuffs manually. Thats it. No secret.
Do it through your code.
Method 1:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
System.setProperty("webdriver.ie.driver","D:\\IEDriverServer_Win32_2.33.0\\IEDriverServer.exe");
WebDriver driver= new InternetExplorerDriver(capabilities);
driver.get(baseURl);
//Identify your elements and go ahead testing...
This will definetly not show any error and browser will open and also will navigate to the URL.
BUT This will not identify any element and hence you can not proceed.
Why? Because we have simly suppressed the error and asked IE to open and get that URL. However Selenium will identify elements only if the browser zoom is 100% ie. default. So the final code would be
Method 2 The robust and full proof way:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
System.setProperty("webdriver.ie.driver","D:\\IEDriverServer_Win32_2.33.0\\IEDriverServer.exe");
WebDriver driver= new InternetExplorerDriver(capabilities);
driver.get(baseURl);
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,"0"));
//This is to set the zoom to default value
//Identify your elements and go ahead testing...
Hope this helps. Do let me know if further information is required.
While setting the IgnoreZoomLevel property allows you to open the browser without error, the test will find no elements at a zoom level other than 100%.
Sending Ctrl+0 will also not always have the expected result, depending on your systems DPI setting. If you have selected Medium (120 dpi) or Larger (144 dpi) (Windows 7 settings) Ctrl+0 will set the zoom to 125% or 150%.
A workaround I found is to set the zoom level according to the DPI settings by editing the setting, before opening IE, in the registry. This does not require administrator rights since everything is located under HKEY_CURRENT_USER.
This is my little helper class I came up with. (C#)
using Microsoft.Win32;
namespace WebAutomation.Helper
{
public static class InternetExplorerHelper
{
private static int m_PreviousZoomFactor = 0;
public static void SetZoom100()
{
// Get DPI setting.
RegistryKey dpiRegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop\\WindowMetrics");
int dpi = (int)dpiRegistryKey.GetValue("AppliedDPI");
// 96 DPI / Smaller / 100%
int zoomFactor100Percent = 100000;
switch (dpi)
{
case 120: // Medium / 125%
zoomFactor100Percent = 80000;
break;
case 144: // Larger / 150%
zoomFactor100Percent = 66667;
break;
}
// Get IE zoom.
RegistryKey zoomRegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Zoom", true);
int currentZoomFactor = (int)zoomRegistryKey.GetValue("ZoomFactor");
if (currentZoomFactor != zoomFactor100Percent)
{
// Set IE zoom and remember the previous value.
zoomRegistryKey.SetValue("ZoomFactor", zoomFactor100Percent, RegistryValueKind.DWord);
m_PreviousZoomFactor = currentZoomFactor;
}
}
public static void ResetZoom()
{
if (m_PreviousZoomFactor > 0)
{
// Reapply the previous value.
RegistryKey zoomRegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Zoom", true);
zoomRegistryKey.SetValue("ZoomFactor", m_PreviousZoomFactor, RegistryValueKind.DWord);
}
}
}
}
I came up with the values comparing the ZoomFactor value in the registry at different system DPI settings with IE zoom set to 100%. There are more than 3 DPI settings in newer Windows versions, so you need to extend the class if you need those.
You could also modify this to calculate any zoom level you want but that was just not relevant for me.
I just call InternetExplorerHelper.SetZoom100(); before opening IE and InternetExplorerHelper.ResetZoom() after closing it.
InternetExplorerOptions options = new InternetExplorerOptions();
options.ignoreZoomSettings() ;
driver = new RemoteWebDriver(new URL("http://localhost:8888/wd/hub"),options);
This basically happens when your browser is set to some zoom level other than 100%(Happens when you scroll mouse on a web page while pressing the Ctrl key.). You can fix this by specifying the code mentioned above to let selenium to ignore the browser zoom level or you can simply open the browser and reset the zoom level to 100% either by going to settings or using a shortcut Ctrl+0(This worked for IE11 and chrome)
Thanks for the post, this really worked for me.
For fixing the zoom level exception:
InternetExplorerOptions options = new InternetExplorerOptions { IgnoreZoomLevel= true };
driver = new InternetExplorerDriver(#"C:\seleniumreferences\IEDriverServer32", options);
Or Goto Internet Explorer Options > Advanced
Check the box for “Reset zoom level for new windows and tabs”.
Click Link to see the image --->
Internet Explorer Options > Advanced
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.IgnoreZoomLevel = true;
driver = new InternetExplorerDriver(driverFilePath, ieOptions);
Set the IgnoreZoomLevel property to true and pass it as InternetExplorerOptions to the driver.
InternetExplorerOptions options = new InternetExplorerOptions();
options.IgnoreZoomLevel = true;
IWebDriver driver = new InternetExplorerDriver(IEDriverLocation,options);
As Tomas Lycken's answer said, there is no language specified, so I will share my solution in Python:
capabilities = DesiredCapabilities.INTERNETEXPLORER
capabilities['ignoreZoomSetting'] = True
driver = webdriver.Ie(capabilities=capabilities)
Working Code using Java
InternetExplorerOptions capabilities= new InternetExplorerOptions();
capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
System.setProperty("webdriver.ie.driver", Constant.drivers + "\\IEDriverServer.exe");
driver = new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();