How to jump between two different elements located same level?

  • In the google chrome inspector console enter the xpath:


    the console returns the element, therefore the xpath is correct.

    But then in the python console I have the result that it does not find the element, the script is:

    import unittest
    from selenium import webdriver
    from import By
    from import WebDriverWait
    from import expected_conditions as EC
    import time
    driver = webdriver.Chrome()
    parentHandle = driver.current_window_handle
    print("Handle principal: " , parentHandle)
    download = driver.find_element(By.XPATH, 
    if download is not None:
    wait = WebDriverWait(driver, 10)
    pass = espera.until(EC.element_to_be_clickable((By.XPATH, 
    if pass is not None:

    I use Python, Selenium Web Driver and Chrome Browser

    thanks who can have any ideas

  • Your xpath locator is wrong , try the below xpath:

    /html/body/div/div/footer/md-toolbar/div/div[2]/img[2]/../../../../../../../../body[@class="layout-column md-dialog-is-showing"]

    The errors were ,

    1. space after /html/body/div/div/footer/md-
    2. more than one space character after body[@class="layout-column
    3. You navigated back to parent only seven times, ../../../../../../.. which brings you back to body element. From here you are again trying to get 'body' which will look for body inside body. But there won't be any such element. You have to navigate back one more time and then search for the body element


    I am not sure why you use such a locator when you can easily get the element by just using the locator

    //body[@class="layout-column md-dialog-is-showing"]

    I hope you are trying to learn xpath and not going to push such a code


    Try to develop best practices like using CSS, IDs , using relative XPaths, using less complex locators etc from initial learning phase only

    Else , you will pickup all the bad practices and will implement in professional life also.

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2