有人可以提示我在硒中定位元素吗?
我要选择的是哪里
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'。 线程“主”中的异常org.openqa.selenium.NoSuchElementException:无法找到元素:.textarea 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'3.6.0',修订版:'6fbf3ec767',时间:'2017-09-27T16:15:26.402Z'
添加我的jar文件和代码
答案 0 :(得分:1)
尝试使用xpath:
WebElement hello = driver.findElement(By.xpath("//div[@placeholder='inputhere~']"));
答案 1 :(得分:1)
该元素是动态元素,因此要向所需元素发送字符序列,您必须诱使 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");
答案 2 :(得分:0)
您认为inputbox
的班级名称错误。您的班级应该是这样。
WebElement hello = driver.findElement(By.className("textarea"));