使用java webdriver一个接一个地选择页面元素有技巧吗?我正在尝试以 iframe 内的形式设置值。
我首先切换 iframe,然后可以访问和更改第一个下拉列表中的值。我可以从其他页面创建 WebElement,但我根本无法与它们交互。
下面的代码允许我更改第一个下拉列表的值。
driver.switchTo().frame(0)
WebElement fromList = driver.findElement(By.id("foo"));
r.selectItemByText(fromList, "var");
之后我无法访问任何元素。我可以毫无错误地找到它们,但我不能对它们做任何事情,因为它说它们没有数据。
WebElement fromList = driver.findElement(By.id("bar"));
r.selectItemByText(fromList, "foo");**
第二行返回此错误:
NoSuchElementException: Cannot locate element with value 'foo'
如果我删除它,我不会收到任何错误,因此代码只会看到元素而不是它的值。