我正在使用Webdriver 2.25.0和Firefox 14
我有以下textarea:
<textarea id="source-text" placeholder="Start typing your text" style="resize: none; overflow: hidden;"></textarea>
我在我的HomePage对象中识别此文本区域,如下所示:
@FindBy(how = How.CSS, using = "div.myclass textarea")
public WebElement columnLeftTextarea;
我想要做的只是在此textarea中键入一些文本,使用以下代码
homePage.columnLeftTextarea.sendKeys("some text");
这会返回以下错误:
Type mismatch Can't assign non-array value to an array
textarea正确定义为我运行时
homePage.columnLeftTextarea.getAttribute("placeholder")
我得到了正确的文字
我甚至尝试通过将功能设置为tnable native events来启动浏览器:
FirefoxProfile ffProfile = new FirefoxProfile(new File(generalPropertiesTestObject.getFirefox_profile_template_location()));
ffProfile.setEnableNativeEvents(true);
FirefoxDriver ffd = new FirefoxDriver(ffProfile);
capabilities = ffd.getCapabilities();
但我仍然得到同样的错误。有没有人对它有任何想法?
答案 0 :(得分:3)
首先尝试专注于textarea。我使用以下代码完成了它:
driver.findElement(By.id("source-text")).clear();
driver.findElement(By.id("source-text")).sendKeys("some text");
它似乎工作正常。
答案 1 :(得分:0)
您需要更改此代码:
@FindBy(how = How.CSS, using = "div.myclass textarea")
public WebElement columnLeftTextarea;
就此:
@FindBy(how = How.ID, using = "source-text")
public WebElement columnLeftTextarea;
首先,它的工作速度更快,因为ID搜索比CSS搜索更快。 其次,ID的变化并不像CSS那么多。