带有来自Selenium 2 / WebDriver的Id的jQuery元素选择器 [英] jQuery element selector with Id from Selenium 2 / WebDriver
本文介绍了带有来自Selenium 2 / WebDriver的Id的jQuery元素选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
((RemoteWebElement)webElement).getId()
来获取元素的ID,它返回一个字符串,如下所示: {e9b6a1cc-bb6f-4740-b9cb-b83c1569d96d}
我想知道这个ID的来源。我正在使用 FirefoxDriver()
,所以这个Firefox相关也许?
有没有办法只有通过知道这个ID来选择一个带有Jquery的元素?
解决方案您不需要访问内部身份证。只需将WebElement实例传递给JavascriptExecutor.executeScript:
$ b
import org.openqa.selenium.JavascriptExecutor; ($)
((JavascriptExecutor)driver).executeScript($(arguments [0])。whatever(),myElement)
I can get an element's ID in Selenium with ((RemoteWebElement) webElement).getId()
, which returns a string like this:
{e9b6a1cc-bb6f-4740-b9cb-b83c1569d96d}
I wonder about the origin of that ID. I am using the FirefoxDriver()
, so is this Firefox related maybe?
Is there a way to select an element with Jquery only by knowing this ID?
解决方案
You don't need to access the internal ID at all. Just pass the WebElement instance to JavascriptExecutor.executeScript:
import org.openqa.selenium.JavascriptExecutor;
((JavascriptExecutor) driver).executeScript("$(arguments[0]).whatever()", myElement)
这篇关于带有来自Selenium 2 / WebDriver的Id的jQuery元素选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文