我怎么能要求硒webdriver的等待一段时间吗?我怎么能、webdriver

2023-09-10 16:52:13 作者:花嫁デ

我可以写下面的code问webdriver的等待一段时间

I can write the following code to ask WebDriver to wait for sometime

new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.id("loginBox")));

不过,

其实我发送Ajax请求到服务器。在这里,我给了20毫秒秒的等待。 20msor 500ms的无所谓。如果响应超过所述给定的时间(例如20毫秒)。然后我会不同的是没有这样的元素中。

Actually I sending AJAX request to the server. Here I gave 20 milli seconds to wait. 20msor 500ms doesn't matter. If the response exceeds the given time (Eg 20ms). Then I'll exception that No Such Element found.

那么,有没有更好的方式来要求服务器等待?

So Is there a better way to ask the server to wait?

谁能帮我?

在此先感谢, Gnik

Thanks in advance, Gnik

推荐答案

您可以确保在employeeName文本框填充,然后再继续执行这一code -

You can make sure that the employeeName text box is populated before you continue with execution with this code -

new WebDriverWait(driver,10).until(new ExpectedCondition<Boolean>() {

        public Boolean apply(WebDriver driver) {                
            String text = driver.findElement(By.id("employeeName")).getText();
            return !text.equals("");
        }
    });

如果在employeeName文本框中的文本为空或不是现在这个code检查。如果是空白的司机等待10秒,如果一些数据被填充在文本字段由于AJAX调用则继续执行。

Now this code checks if the text in the employeeName text box is blank or not. If it is blank the driver waits for 10 seconds or if some data gets populated in the text field due to the AJAX call then it continues with execution.

如果你可以发布您的某些code。通过您正在AJAX调用。这不起作用

If this does not work can you post some of your code by which you are making the AJAX call.

 
精彩推荐