Internet Explorer中的Selenium WebDriver单击问题 [英] Selenium WebDriver Click issue in Internet Explorer

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

问题描述

在多个Windows 7测试工作站上使用Selenium WebDriver.

Using Selenium WebDriver on several Windows 7 test workstations.

Button的FireBug Html列出如下:

FireBug Html of Button is listed below:

<input type="submit" style="border-color:Black;border-width:1px;border-style:solid;
font-family:tahoma,arial;font-size:0.7em;" id="UserPassword1_LoginButton" 
onclick="javascript:WebForm_DoPostBackWithOptions(new  WebForm_PostBackOptions(&quot;UserPassword1$LoginButton&quot;, 
&quot;&quot;, true, &quot;UserPassword1&quot;, &quot;&quot;, false, false))" value="Log      In" name="UserPassword1$LoginButton">

下面是Selenium C#代码段:

A snippet of Selenium C# code is below:

try
        {
            // Click on the button identified by Id
            IWebElement query = Driver.FindElement(By.Id(strControl));
            query.Click();
        }

在某些Windows测试工作站上,单击按钮的方法效果很好.在其他Windows 7测试工作站上,单击按钮不会按按钮,而是将按钮突出显示.

On some windows test workstations the button click method works just fine. On other Windows 7 test workstations the button click does not press the button, The button is just highlighted.

我也看到过类似的问题,有时我必须包括两个:

I also have seen a similar problem where some times I have to include two:

query.Click();

连续

命令以获取要按下的按钮.

commands in a row to get the button to press.

我们一直在试图找出环境之间的区别,但没有提出任何解决方案.

We have been trying to figure out what is different between environments but are not coming up with any solutions.

有关如何解决此问题或是否有人可以解决此问题的任何想法.

Any ideas on how to troubleshoot this problem or if anyone has a solution to this problem.

谢谢

推荐答案

您还没有说过遇到什么问题的浏览器,但是我将使用自己的心理调试能力来推断您可能是在谈论Internet Explorer. IE驱动程序存在已知的挑战.

You haven't said what browser(s) you're seeing the problem with, but I'm going to use my psychic debugging powers to deduce that you're probably talking about Internet Explorer. There are known challenges with the IE driver.

一组挑战是您需要将浏览器的缩放级别设置为100%,否则IE驱动程序无法计算坐标以正确单击.当单击在一台计算机上有效而在另一台计算机上无效时,通常是这种情况,这在项目Wiki 中有说明.

One set of challenges is that you need to set the zoom level of the browser to 100%, or the IE driver can't calculate the coordinates to click on properly. This is often the case when clicking works on one machine but not another, and is documented in the project wiki.

另一类问题尤其涉及窗口焦点.一种替代方法是仅将模拟事件用于IE驱动程序.这种方法有其自身的陷阱,但在您遇到的情况下可能会起作用.由于您提到使用的是C#,因此以下是.NET绑定的代码以禁用本机事件.

Another class of problems deals in particular with window focus. One alternative is to only use simulated events for the IE driver. This approach has its own pitfalls, but it may work in your situation. Since you mentioned that you're using C#, here is the code for the .NET bindings to disable native events.

InternetExplorerOptions options = new InternetExplorerOptions();
options.EnableNativeEvents = false;
IWebDriver driver = new InternetExplorerDriver(options);

这篇关于Internet Explorer中的Selenium WebDriver单击问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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