When using the IE driver with IE9, occasionally the Click method will only select a button, it wont do the action of the Click(). Note this only happens occasionally, so i d
None of the above solutions worked for me. This did the trick tho:
element.sendKeys(org.openqa.selenium.Keys.CONTROL);
element.click();
element << org.openqa.selenium.Keys.CONTROL
element.click()
Or, if you're using Geb, there's an even better solution that's completely unobtrusive:
(tested with IE7 and Geb 0.7.0)
abstract class BaseSpec extends geb.spock.GebSpec
{
static
{
def oldClick = geb.navigator.NonEmptyNavigator.metaClass.getMetaMethod("click")
def metaclass = new geb.navigator.AttributeAccessingMetaClass(new ExpandoMetaClass(geb.navigator.NonEmptyNavigator))
// Wrap the original click method
metaclass.click = {->
delegate << org.openqa.selenium.Keys.CONTROL
oldClick.invoke(delegate)
}
metaclass.initialize()
geb.navigator.NonEmptyNavigator.metaClass = metaclass
}
}
class ClickSpec extends BaseSpec
{
def "verify click"()
{
given:
to HomePage
expect:
waitFor { at HomePage }
when:
dialog.dismiss()
// Call the wrapped .click() method normally
$('#someLink').click()
then:
waitFor { at SomePage }
}
}
class HomePage extends geb.Page
{
static url = "index.html"
static at = { title == "Home - Example.com" }
static content = {
dialog { module DialogModule }
}
}
class SomePage extends geb.Page { ... }
class DialogModule extends geb.Module { def dismiss() { ... } }
In my case, clicking in IE7 appeared to fail whenever it was preceded by the closing of an animated modal overlay (we're using jQuery Tools Overlay Modal Dialog). The Geb method above solved this problem.
Another one:
WebDriver: * Firefox 18 support. * IEDriver supports "requireWindowFocus" desired capability. When using this and native events, the IE driver will demand focus and user interactions will use SendInput() for simulating user interactions. Note that this will mean you MUST NOT use the machine running IE for anything else as the tests are running.
WebdriverJS
In IE when you are attempting to perform an click() action, the URL keeps blink on status bar. It means the driver is focusing on the element and trying to perform click() action. In order to complete its click() action, i used sleep() method before and after every click action.
Try this example.
var webdriver = require('..'), By = webdriver.By, until = webdriver.until;
var driver = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'ie' }).build();
driver.get('http://www.google.com')
.then(function(){
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(1000 * 3);
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).then(function(button){
button.click();
});
})
.then(function(){
driver.findElement(By.css('div[class="gb_Zb"] a[title="Google Apps"]')).then(function(apps){
apps.click();
driver.findElements(By.css('a[class="gb_O"]')).then(function(appsList){
console.log("apps : "+appsList.length);
for(var i = 0; i < appsList.length; i++){
console.log('applications : '+i);
if(i == 5) {
var element = appsList[i];
driver.sleep(1000 * 5);
driver.executeScript("var tmp = arguments[0]; tmp.click()", element);
driver.sleep(1000 * 5);
} } })
})
})
.then(null, function(err) {
console.error("An error was thrown! By Promise... " + err);
});
driver.quit();
to perform click we can use any of these, tested on IE
element.click();
driver.actions().click(element).perform();
driver.executeScript("var tmp = arguments[0]; tmp.click()", element);
I have found the same thing on Internet Explorer 8 when attempting to click links using .Click()
- even though I can see Selenium clicking on the link. From my experience it appears that if the browser does not have focus then the initial click doesn't work.
A workaround to this is to send a .Click()
to another element on the page, so that the browser gets the focus, before attempting to click the link, e.g. it's parent:
Driver.FindElement(By.Id("Logout")).FindElement(By.XPath("..")).Click();
Driver.FindElement(By.Id("Logout")).Click();
Short answer:
If you're running an automated Selenium test in IE11 with the browser window open on a touch screen monitor (e.g. Windows 8 touch laptop), try running the test with the browser window open in a non-touch screen.
The original .click() method should work fine without all the code workarounds.
Answer background:
I worked with a tester in our QA team to investigate a similar issue. After trying most of the code solutions here and at selenium webdriver IE button issue, we eventually found the problem only happened in IE (version 11 for us) on the tester's Windows 8 laptop touch screen.
Running the Selenium test with the IE window running on their external Dell monitor allowed the test to run fine every time, even using just the standard .click() call.
We were also failing on the click event for a button in a Magnific Popup (http://dimsemenov.com/plugins/magnific-popup/) dialog.
My hypothesis: there is a problem with how IE11 (not sure about other versions) handles the translation of touch events to/from mouse click events on touch screens.
Try setting Internet Options -> Security -> Enable Protected Mode to the same setting for all zones, see http://www.mail-archive.com/watir-general@googlegroups.com/msg13482.html. This is from the Watir googlegroup, but in my Selenium 2 tests IE button clicks seem to work better after applying this.