Selenium WebDriver在Internet Explorer中单击问题

Joe*_*itz 5 selenium internet-explorer xpath webdriver selenium-webdriver

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

FireBug Html of Button如下:

<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">
Run Code Online (Sandbox Code Playgroud)

下面是一段Selenium C#代码:

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

在某些Windows测试工作站上,按钮单击方法工作得很好.在其他Windows 7测试工作站上,按钮单击不按下按钮,按钮刚刚突出显示.

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

query.Click();
Run Code Online (Sandbox Code Playgroud)

连续命令按下按钮.

我们一直试图弄清楚环境之间有什么不同,但没有提出任何解决方案.

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

谢谢

Jim*_*ans 20

您还没有说过您遇到问题的浏览器,但我将使用我的通灵调试功能来推断您可能正在谈论Internet Explorer.IE驱动程序存在已知的挑战.

一组挑战是您需要将浏览器的缩放级别设置为100%,否则IE驱动程序无法计算要正确点击的坐标.通常情况下,单击一台计算机上的工作而不是另一台计算机上的工作,并记录在项目维基中.

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

InternetExplorerOptions options = new InternetExplorerOptions();
options.EnableNativeEvents = false;
IWebDriver driver = new InternetExplorerDriver(options);
Run Code Online (Sandbox Code Playgroud)