Javascript 如何通过 Selenium IDE 模拟鼠标点击网站空白区域?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27966080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:01:09  来源:igfitidea点击:

How to simulate mouse click on blank area in website by Selenium IDE?

javascriptseleniumwebautomationqa

提问by Idan E

I want to perform mouse click on blank area outside a form in order to wake up the data traffic in some website by Selenium IDE. Any ideas?

我想在表单外的空白区域执行鼠标单击,以便通过 Selenium IDE 唤醒某些网站中的数据流量。有任何想法吗?

I've tried to do click by x,y but it doesn't effective for my test case. The scenario is below:

我试过按 x,y 点击,但它对我的测试用例无效。场景如下:

  1. fill the email field
  2. click outside the form in order to make the client to send data request to the server for check if this email is already exist in the DB and then it does auto complete and enable the continue button.
  1. 填写电子邮件字段
  2. 单击表单外部以使客户端向服务器发送数据请求以检查该电子邮件是否已存在于数据库中,然后它会自动完成并启用继续按钮。

回答by Manu Singh

You can use the command:

您可以使用以下命令:

driver.findElement(By.xpath("//html")).click();

But sometimes it doesnt take blank spaces,

但有时它不需要空格,

In such cases, use:

在这种情况下,请使用:

driver.get("//html");

回答by CharlesC

'html' is a special element, what you want is 'body' (the first DOM element that is 'visible')

'html' 是一个特殊的元素,你想要的是 'body'(第一个 DOM 元素是 'visible')

so please use the following (tested with Chrome confirme working with no problem):

所以请使用以下内容(使用 Chrome 确认工作没有问题):

python example driver.find_element_by_xpath("//body").click()

蟒蛇示例 driver.find_element_by_xpath("//body").click()

回答by Usman Kokab

The best solution is to just use the keyboard TABkey by executing the following statement.

最好的解决方案是TAB通过执行以下语句只使用键盘键。

element.sendKeys(Keys.TAB);

It will focus the next element - thus out of the field - and you will get your desired result.

它将聚焦下一个元素 - 因此不在该领域 - 您将获得所需的结果。

回答by Alexander angelov

Just click on another element on the page you are sure is present.

只需单击您确定存在的页面上的另一个元素。

Browser.Driver.FindElement(By.Id("testtest123")).Click();

Another solution may be to invoke javascript removing the focus from that email field, it depends on the trigger you have set for the ajax to trigger.

另一种解决方案可能是调用 javascript 从该电子邮件字段中删除焦点,这取决于您为 ajax 设置的触发器。

回答by V Λ C U U M

I hope it still can help people, so i have the answer =) Selenium always throws exceptions on simple click if dropdown, field or whatever makes other buttons inactive. The way out for me was to use actions with pause. Here are some code rows from my example:

我希望它仍然可以帮助人们,所以我有答案 =) 如果下拉菜单、字段或任何使其他按钮处于非活动状态,Selenium 总是在简单点击时抛出异常。我的出路是使用暂停的动作。以下是我的示例中的一些代码行:

Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath("your path")))
       .click().pause('your amount of milliseconds').click().build().perform();

Wrap it into some function and there you go, you have a new clicker.

将它包装到某个函数中,然后你就有了一个新的点击器。

回答by Metin Atalay

I need to click in a blank area in the react code.

我需要点击反应代码中的空白区域。

The below code is fixed my issue.

下面的代码解决了我的问题。

 driver.FindElement(By.XPath("//body")).Click();

回答by Hideandseek

Once email is filled, to click blank area, use this command.

填写电子邮件后,要单击空白区域,请使用此命令。

driver.findElement(By.xpath("//html")).click();

driver.findElement(By.xpath("//html")).click();

It will click blank area.

它将单击空白区域。