Selenium 不单击 InternetExplorerDriver 按钮的解决方法 [英] Workarounds for Selenium not clicking button with InternetExplorerDriver

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

问题描述

我在网页上有一个按钮,当我通过 IE 运行时,Webdriver 无法点击该按钮 - 我已经尝试了以下解决方法,但没有成功 -

I've got a button on a webpage that Webdriver will not click when I'm running via IE - I've tried the below workarounds but no luck -

通过Javascript点击:

Clicking via Javascript:

((JavascriptExecutor) driver).executeScript("$(arguments[0]).click()", webElement)

使用 SendKeys:

Using SendKeys:

webElement.SendKeys(keys.Enter)

使用动作生成器

Actions test = new Actions(driver);
        test.moveToElement(webElement);
        test.clickAndHold();
        test.release();
        test.build();
        test.perform();

确保窗口是活动窗口,然后单击父对象,然后单击对象本身

Making sure the window is the active one, then clicking on the parent object, then the object itself

问题是,它们都不起作用.我已经检查了 Firefox 和 Chrome,脚本运行良好.我已经确认在使用 IE 时找到了该元素.我可以尝试其他解决方法吗?

Problem is, none of them work. I've checked in Firefox and Chrome and the script runs fine. I've confirmed that the element is being found when using IE. Are there any other workarounds I can try?

推荐答案

似乎您很想使用 JQuery 样式的单击...正常的 javascript 样式的单击应该可以工作.

Seems you are tyring to use JQuery style click... normal javascript style click should work.

试试这个:

((JavascriptExecutor) driver).executeScript("arguments[0].click();", webElement)

我总是发现通过以下方式在 IE 中单击元素是成功的.

I always found successful with the following for clicking an element in IE.

  1. 如果是复选框/单选框:webElement.click();
  2. 可点击的输入元素:webElement.sendKeys("\n");
  3. 对于其他元素,使用上面说的 JS 样式点击.

这篇关于Selenium 不单击 InternetExplorerDriver 按钮的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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