有人能给我一个提示在硒中找到一个元素吗?
我试图选择的是哪里
WebElement hello = driver.findElement(By.className("input-box"));
Eclipse出错:
Can't find symbol 'GetGraphicsResetStatus'.
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: .input\-box
再次感谢你。
原始的HTML
<div data-v-7d31c51a="" data-v-126e1ccf="" class="input-box"><textarea data-v-7d31c51a="" placeholder="inputhere~" maxlength="500" autofocus="autofocus" class="textarea" style="height: 60px;"></textarea><div data-v-7d31c51a="" class="indicator" style="bottom: -30px; right: 100px;"><span data-v-7d31c51a="" class="">0</span>/<span data-v-7d31c51a="">500</span></div></div>
尝试WebElement时出错hello = driver.findElement(By.className(“textarea”));
找不到符号'GetGraphicsResetStatus'。线程“main”中的异常org.openqa.selenium.NoSuchElementException:无法找到元素:.textarea有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html构建信息:版本:'3.6.0',版本:'6fbf3ec767',时间: '2017-09-27T16:15:26.402Z'
添加我的jar文件和我的代码
试试xpath:
WebElement hello = driver.findElement(By.xpath("//div[@placeholder='inputhere~']"));
元素是一个动态元素,因此要将字符序列发送到所需元素,您必须引导WebDriverWait才能使元素可单击,并且您可以使用以下任一解决方案:
cssSelector
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.input-box>textarea.textarea[placeholder^='inputhere']"))).sendKeys("JohnMax");
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='input-box']/textarea[@class='textarea' and starts-with(@placeholder, 'inputhere')]"))).sendKeys("JohnMax");
您已经考虑过inputbox
的错误的类名。您的类应该是。
WebElement hello = driver.findElement(By.className("textarea"));