来自Selenium 2 / WebDriver的Id的jQuery元素选择器
我可以在Selenium中使用((RemoteWebElement) webElement).getId()
获取元素的ID,它返回如下字符串:
{e9b6a1cc-bb6f-4740-b9cb-b83c1569d96d}
我想知道该ID的来源。 我正在使用FirefoxDriver()
,所以这个Firefox有关吗?
有没有办法只通过知道这个ID来选择一个带有Jquery的元素?
您根本不需要访问内部ID。 只需将WebElement实例传递给JavascriptExecutor.executeScript:
import org.openqa.selenium.JavascriptExecutor; ((JavascriptExecutor) driver).executeScript("$(arguments[0]).whatever()", myElement)
这个多个字母和数字的ID是浏览器DOM中与您的WebElement对象相对应的节点的内部标识符。
要获取属性“id”的值,必须使用getAttribute方法:
String id = myElement.getAttribute("id");
要通过’id’属性选择元素,您必须使用findElement方法,如下所示:
WebElement myElement = driver.findElement(By.id("my_element_id"));
如果你想使用jQuery选择器,你必须使用如下的findElement方法(假设你知道它是’div’元素):
WebElement myElement = driver.findElement(By.cssSelector("div#my_element_id"));
- 使用selenium的java出错:预期
- 无法使用IEDriver单击IE上的链接
- Selenium在一台计算机上发生了“UnreachableBrowserException / Address has in use”
- 我在哪里可以找到明确的Selenium WebDriver到Firefox兼容性矩阵?
- 如何使用Selenium webdriver和Java为firefox设置代理?
- 在PATH中找不到firefox二进制文件。 确保安装了firefox。 操作系统似乎是:VISTA
- 使用Selenium在FireFox中设置首选项时出现mime类型问题
- 编写一个firefox插件并从java应用程序访问它
- Selenium测试运行不会保存cookie?