There are a couple of options there. The sample code is in Java, but a port to other languages should be straightforward.
WebElement myElement = driver.findElement(By.id("myDiv"));
WebElement parent = (WebElement) ((JavascriptExecutor) driver).executeScript(
"return arguments[0].parentNode;", myElement);
WebElement myElement = driver.findElement(By.id("myDiv"));
WebElement parent = myElement.findElement(By.xpath("./.."));
WebElement
Note: As you can see, for the JavaScript version you'll need the driver
. If you don't have direct access to it, you can retrieve it from the WebElement
using:
WebDriver driver = ((WrapsDriver) myElement).getWrappedDriver();