使用以前使用Selenium 2选择器选择的Jquery选择一个元素 [英] Select an element with Jquery previously selected with Selenium 2 selector

查看:108
本文介绍了使用以前使用Selenium 2选择器选择的Jquery选择一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我选择了Selenium WebElement,例如:

I have a Selenium WebElement selected, for example like this:

WebElement element = webDriver.findElement(By.xpath('//div/span[@id='test']'));

如果我不知道如何找到这个元素,我如何用JQuery选择相同的元素?我只有webDriver实例和元素实例。

If i have no knowledge about how i found this element, how can i select the same element with JQuery? All i have is the webDriver instance and the element instance.

在伪代码中说,我想要这样的东西:

Spoken in "pseudo-code", i want something like this:

webDriver.executeScript("$(" + element.getUniqueSelector() + ").attr('id', 'test2')");

/ edit

我得到了答案:带有来自Selenium 2的Id的jQuery元素选择器/ WebDriver

推荐答案

以下是答案:带有来自Selenium 2 / WebDriver的Id的jQuery元素选择器

import org.openqa.selenium.JavascriptExecutor;

((JavascriptExecutor) driver).executeScript("$(arguments[0]).whatever()", myElement)

这篇关于使用以前使用Selenium 2选择器选择的Jquery选择一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆