2

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

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

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

I got my answer: jQuery element selector with Id from Selenium 2 / WebDriver

Community
  • 1
  • 1
Alp
  • 29,274
  • 27
  • 120
  • 198
  • This is basically the other direction to this question: http://stackoverflow.com/q/5490523/675065 – Alp Apr 09 '11 at 14:46

1 Answers1

2

Here is the answer: jQuery element selector with Id from Selenium 2 / WebDriver

import org.openqa.selenium.JavascriptExecutor;

((JavascriptExecutor) driver).executeScript("$(arguments[0]).whatever()", myElement)
Community
  • 1
  • 1
Alp
  • 29,274
  • 27
  • 120
  • 198