selenium find parent element code example

Example 1: retrieving parent element from child aWebelement selenium java

WebElement myElement = driver.findElement(By.id("myDiv"));
WebElement parent = (WebElement) ((JavascriptExecutor) driver).executeScript(
                                   "return arguments[0].parentNode;", myElement);

Example 2: selenium select parent element

parent_element = element.find_element_by_xpath('./..')

Example 3: selenium get element parent

//label[contains(., 'labelName')]/parent::*//input[@value='elementToSelect']