我想在此 website 处添加辅助文本字段文本字符串。
我的 Selenium 方法如下所示:
public void addSecondaryText(String string) {
//click secondary button
WebElement secButton = driver.findElement(By.xpath("//label/input[@id='sub-text-check']"));
if (secButton.isDisplayed()) {
secButton.click();
}
//clear text
WebElement secTextField = driver.findElement(By.xpath("//*[@id='sub-text']"));
secTextField.clear(); // I get the exception here!
//add text
secTextField.sendKeys(string);
}
但是,我目前遇到 secTextField.clear();
异常,无法对其进行操作:
Exception in thread "main" org.openqa.selenium.InvalidElementStateException: invalid element state: Element is not currently interactable and may not be manipulated
有什么建议我做错了什么吗?
感谢您的回复!
最佳答案
这里的问题是文本区域依赖于另一个按钮,您需要先单击它才能使文本区域可编辑。请参见下图。
//List will help of to determine the "Add secondary text" button needs to be clicked on not
//if the count is greater than 0 then click it
IList<IWebElement> elements = driver.FindElements(By.XPath("//span[contains(text(),'Add secondary text')]"));
if (elements.Count>0)
{
elements.FirstOrDefault().Click();
}
IWebElement element = driver.FindElement(By.Id("sub-text"));
element.Clear();
element.SendKeys("Test");
关于java - 找到复选框并添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30697747/