首页 > 解决方案 > 无法在表单类或 div 类中找到元素

问题描述

我无法在表单类或 div 类中找到元素:

//Tried this clicking on Source name.
driver.findElement(By.id("__BVID__62")).click();
//Typing into Source name.
driver.findElement(By.id("__BVID__63")).sendKeys(new String[]{"CNN"});

我试过这个:

driver.findElement(By.xpath("//input[contains(@class='form-control') and type='text']")).sendKeys("CNN");

HTML 代码:

<div class="card-body">
<fieldset id="_BVID__62" role="group" aria-labelledby="__BVID__62__BV_label" class="b-form-group form-group">
<legend id="_BVID__62__BV_label" class="col-form-label pt-0">Source Name</legend>
<div role="group" aria-labelledby="_BVID__62__BV_label" class="">
<input id="__BVID__63" type="text" class="form-control">

标签: seleniumautomated-tests

解决方案


使用此代码:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement input = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='card-body']/descendant::div/input[contains(@id,'BVID')]")));
input.sendKeys("CNN");

推荐阅读