我可以让硒暂停输入并在触发器上恢复吗? [英] Can I make selenium pause for input and resume on a trigger?

查看:91
本文介绍了我可以让硒暂停输入并在触发器上恢复吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道硒能在下面做吗?我想自动执行 自动化流程的某些部分:

I am wondering if selenium can do below? I want to automate only certain parts of the automation flow:


  1. 加载a网页(使用angular构建),使用一些
    预定义输入提交表单

  2. 在下一页上,自动填写一些
    数据,如前所述,但等待我在特定的
    输入字段中填写一些输入(不能硬编码这些数据)

  3. 此后,触发器(如按钮
    按或密钥组合;在网页之外)应继续使用剩余的自动流程并在第3页和第4页中降落
    ,依此类推。

我熟悉的唯一选项是在浏览器> inspect> console中编写和运行修改表单元素的自定义JS。对于上面,我将不得不在每个页面上运行不同的功能。为此,我可以注释除了所需的函数调用之外的所有函数并运行它。我想我不能从控制台中选择和运行代码的一部分(例如第1页)。

The only option I am familiar with is to write and run custom JS that modifies form elements, in the browser>inspect>console. For above, I'll have to run different functions on each page. For doing this, I can comment out all but the required function call and run it. I think I cannot select and run only one part of the code (for page 1 for example) from the console.

PS:如果任何严格的SO人都认为这个是不是适合SO,还有一个好的(以自动化为中心?)的地方要求为这种东西找到合适的工具?

PS: If any of the strict SO folks think this is not fitting SO, where else is a good (automation focused?) place to ask for finding the right tools for this kind of stuff?

推荐答案

选项1:

这可以使用显式等待轻松实现。假设您要在某个字段中手动输入数据。您可以让selenium等到字段包含值的位置(其value属性不为空)。例如:

This can be easily achieved using Explicit wait. Suppose you want to manually enter data in some field. You can make the selenium wait till the point where the field contains a value(Its "value" attribute is not empty). Ex:

WebDriverWait wait = new WebDriverWait(driver, 100);
//whatever time you think is sufficient for manually entering the data.
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id(>someid>)));
if(ExpectedConditions.attributeToBeNotEmpty(element,"value"))
{
  //continue with the automation flow
}

选项2:

有点hacky。你可以做的是,在执行开始时打开另一个标签,然后切换回原来的标签,如下所示:

It is kinda hacky. What you can do is, At the beginning of the execution open another tab and then switch back to your original one, like this:

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
driver.switchTo().defaultContent();

现在执行将开始,并且您希望脚本停止,以便您手动输入数据,在这样的无限循环中从selenium中检索所有选项卡 -

Now execution will start and at the point where you want the script to stop for you to manually enter your data, retrieve all the tabs from selenium in an infinite loop like this-

for(int i =1;i>0;i++)
{
 ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
 if(tabs.size()==2)
 {
  //keep checking for the point when the number of tabs becomes 1 again.
  continue;
 }
 else
 {
  break;
 }
}
//your rest of the automation code

想法是让selenium暂停执行(因为它会卡在循环中),直到标签数量再次变为1.在此期间,输入数据并关闭空标签,以便selenium可以继续执行执行。

The idea is to make selenium pause the execution(since it will be stuck in the loop) till the point where number of tabs again become 1. During this, you enter your data and close the empty tab so that the selenium can continue its execution.

您也可以尝试这个

这篇关于我可以让硒暂停输入并在触发器上恢复吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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