Selenium 2.0b3 IE WebDriver,单击不触发 [英] Selenium 2.0b3 IE WebDriver, Click not firing

查看:128
本文介绍了Selenium 2.0b3 IE WebDriver,单击不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当将IE驱动程序与IE9一起使用时,Click方法有时只会选择一个按钮,而不会执行Click()的操作.请注意,这只是偶尔发生,所以我不认为这是问题所在的代码.在Firefox4中使用Firefox驱动程序没有问题.我还遇到一个问题,即有时也不会在IE中找到元素,而只是在IE中而不是Firefox.

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 don't think it is the code that is the problem. Using the Firefox driver with Firefox4 has no problems. I am also having an issue where elements are not being found occasionally too, but only in IE again, not Firefox.

if (Driver.FindElement(By.Name("username")) == null) {
    //sometimes gets here in IE, never gets here in Firefox
}
Driver.FindElement(By.Name("username")).SendKeys(username);
Driver.FindElement(By.Name("surname")).SendKeys(surname);
Driver.FindElement(By.Name("firstname")).SendKeys(firstname);
string url = Driver.Url;
Driver.FindElement(By.Name("cmd")).Click();
if (Driver.Url == url) {
    //if the page didnt change, click the link again
    Driver.FindElement(By.Name("cmd")).Click();
}

我已经看到了类似的问题(http://stackoverflow.com/questions/4737205/selenium-webdriver-ie-button-issue),但是我没有动态生成的ID.

I have seen this similar questions (http://stackoverflow.com/questions/4737205/selenium-webdriver-ie-button-issue), but i do not have dynamicly generated ids.

推荐答案

尝试使用.Click()单击链接时,我在Internet Explorer 8上发现了相同的内容-尽管我看到Selenium也单击了链接.根据我的经验,如果浏览器没有焦点,则初始单击将不起作用.

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.

一种解决方法是将.Click()发送到页面上的另一个元素,以便浏览器获得焦点,然后再尝试单击链接,例如是父母:

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();

这篇关于Selenium 2.0b3 IE WebDriver,单击不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆