Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaWebDriver-利用WebElement.submit()的阻塞时间_Java_Selenium_Webdriver - Fatal编程技术网

JavaWebDriver-利用WebElement.submit()的阻塞时间

JavaWebDriver-利用WebElement.submit()的阻塞时间,java,selenium,webdriver,Java,Selenium,Webdriver,短版本:WebElement.submit()被阻止;因此,我不能利用呈现的时间页来做其他事情 长版本: 我正在使用WebDriver Java客户端库2.16.1 我有一个自动测试,可以串行进行,但可以并行进行(基本上登录到n个不同的用户来检查状态)。因此,我尝试使用线程使其同时运行:同时启动多个Firefox实例 示例代码: public class FirefoxRunnable implements Runnable { @Override public void ru

短版本:WebElement.submit()被阻止;因此,我不能利用呈现的时间页来做其他事情


长版本:

我正在使用WebDriver Java客户端库2.16.1

我有一个自动测试,可以串行进行,但可以并行进行(基本上登录到n个不同的用户来检查状态)。因此,我尝试使用线程使其同时运行:同时启动多个Firefox实例

示例代码:

public class FirefoxRunnable implements Runnable {
    @Override
    public void run() {
        WebDriver d = new FirefoxDriver();
        d.get("http://www.facebook.com");
        d.findElement(By.id("email")).sendKeys("username");
        d.findElement(By.id("pass")).sendKeys("password");
        d.findElement(By.id("pass")).submit();
    }
}

public static void test() {
    Thread t1 = new Thread(new FirefoxRunnable("Thread 1"));
    Thread t2 = new Thread(new FirefoxRunnable("Thread 2"));
    t1.start();
    t2.start();
}
问题:
d.findElement(By.id(“pass”)).submit()在加载页面时被阻止


关于如何利用加载的时间页面做一些有用的事情,您有什么建议吗?

实际上您不能。最终,d.findElement(By.id(“pass”)).submit()必须由CPU执行,如果它是阻塞调用,那么它将利用CPU(我在单核上下文中讨论所有这些)。但是,现代操作系统将为每个线程提供一个时间片,因此不需要从开始到结束所有时间都由d.findElement(by.id(“pass”)).submit()占用。CPU基本上会给您的其他线程和父线程执行的机会。

您可以选择模拟按键“Keys.ENTER”,这不会阻塞,然后您可以显式等待或在您的睡眠循环中查找元素主体标记(或任何不阻塞的方法),例如>

for loop{
   if not found() //found (e.g findElement(body)) is non blocking, make sure no implicit wait
        sleep(3 secs)  // while sleep utilize this time
 }

我实际上认为它是阻塞的,因为它是由一个繁忙的等待循环实现的,等待浏览器加载完页面并返回。