这是我尝试查找所选输入的HTML
我尝试将key()发送到此输入
String xPath = "//*[@id='id_username']";
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xPath))).sendKeys("text");
始终收到此错误org.openqa.selenium.TimeoutException
。通常,当元素在设置的时间内不可见时,我会收到此错误。
整个html中没有iframe。
可能是什么原因?
答案 0 :(得分:1)
您需要考虑以下几点:
String
尝试将 xpath 定义为By
的对象。sendKeys()
而不是 ExpectedConditions 方法时,向前移动 visibilityOfElementLocated()使用 elementToBeClickable()方法。<input>
尝试构建粒度 xpath 您的代码块将为:
By xPath = By.xpath("//form[@action='/accounts/register/']/fieldset[@class='fieldset_main']//input[@id='id_username' and @name='username']");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(xPath)).sendKeys("text");