gpt4 book ai didi

java - 找到复选框并添加文本

转载 作者:行者123 更新时间:2023-11-30 08:08:53 25 4
gpt4 key购买 nike

我想在此 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");

enter image description here

关于java - 找到复选框并添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30697747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com