Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Selenium Webdriver等待预期条件失败:等待由.id定位的元素的可见性_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium Webdriver等待预期条件失败:等待由.id定位的元素的可见性

Selenium Webdriver等待预期条件失败:等待由.id定位的元素的可见性,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我试图让selenium web驱动程序等待,但我总是遇到异常” org.openqa.selenium.TimeoutException:预期条件失败:等待by.id:mobileNo定位的元素的可见性(尝试20秒,间隔100毫秒)” 我把秒数增加到100,然后也遇到了同样的问题,我的id是正确的 WebDriver d = new ChromeDriver(); d.get("http://myurlOne"); WebElement username = d.fin

我试图让selenium web驱动程序等待,但我总是遇到异常”

org.openqa.selenium.TimeoutException:预期条件失败:等待by.id:mobileNo定位的元素的可见性(尝试20秒,间隔100毫秒)”

我把秒数增加到100,然后也遇到了同样的问题,我的id是正确的

    WebDriver d = new ChromeDriver();
    d.get("http://myurlOne");
    WebElement username = d.findElement(By.id("username_id"));          
    username.sendKeys("123");
    WebElement password = d.findElement(By.id("password_id"));
    password.sendKeys("123");
    d.findElement(By.id("loginButton")).click();
    System.out.println("logged in successfully");
    d.get("http://navigatedurl");
    JavascriptExecutor js = (JavascriptExecutor)d;  
    System.out.println("navigated to new page"); 
    WebDriverWait wait__mob = new WebDriverWait(d, 20);
    try {
        System.out.println("Start"+new Date());
        wait__mob .pollingEvery(100,TimeUnit.MILLISECONDS).until(ExpectedConditions.visibilityOfElementLocated(By.id("mobileNo")));
        d.findElement(By.id("mobileNo")).sendKeys("99999999999);
    } catch (TimeoutException e) {
        // TODO: handle exception
        System.out.println(e.toString());
    } 
分区代码:

 <div class="form-group">
   <label class="col-xs-5 control-label" for="mobileNo">Mobile No.</label>
     <div class="col-xs-6 leftpadding-none">
        <input type="tel" class="form-control k-input" id="mobileNo" 
       name="inputmobileNo" placeholder="" maxlength="10"> <!--required 
       pattern="\d{10}" validationMessage="Mobile No. is Required"-->
  </div>

流动电话号码。

根据类的Java文档,如果要更改轮询间隔,则需要在构造函数中进行更改,因为构造函数如下所示:

WebDriverWait(WebDriver driver, long timeOutInSeconds, long sleepInMillis)

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.
在您试图调用元素上的
sendKeys()
时,继续前进,您需要调用
ExpectedConditions
方法

因此,您的代码将是:

WebDriver d = new ChromeDriver();
d.get("http://myurlOne");
WebElement username = d.findElement(By.id("username_id"));          
username.sendKeys("123");
WebElement password = d.findElement(By.id("password_id"));
password.sendKeys("123");
d.findElement(By.id("loginButton")).click();
System.out.println("logged in successfully");
d.get("http://navigatedurl");
System.out.println("navigated to new page"); 
WebDriverWait wait__mob = new WebDriverWait(d, 20);
try {
    System.out.println("Start"+new Date());
    wait__mob.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='form-group']//label[contains(.,'Mobile No.')]//following::div[1]/input[@class='form-control k-input' and @id='mobileNo' and @type='tel']"))).sendKeys("9999999999);
} catch (TimeoutException e) {
    System.out.println(e.toString());
} 

页面的html是什么?你需要检查的是真实的div吗?你得到了异常,因为你没有正确处理异常,元素在20秒后没有定位。它的真实div。我检查了datyes元素在20秒后没有定位,我也尝试了100秒,den也得到了相同的。检查它是否在一个框架内?谢谢你的回复,我尝试了你的代码。但第一次它工作,第二次它不工作“org.openqa.selenium.TimeoutException:预期条件失败:等待元素可点击:By.xpath://input[@class='form-control k-input'和@id='mobileNo'](尝试20秒,间隔100毫秒)“我没有使用任何帧,只有div..is可能是原因?当我尝试元素可见测试时,有时元素不可见,我认为驱动程序运行后元素会出现,直到出现相同的错误。.org.openqa.selenium.TimeoutException:预期条件失败:等待元素可点击:By.xpath://input[@class='form-control k-input'和@id='mobileNo'](尝试了20秒)间隔100毫秒)我没有使用frame.its full div。我们没有使用frameELEMENT