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 selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time driver = webdriver.Chrome() driver.get("http://portalapps.vtr.cl") parentHandle = driver.current_window_handle print("Handle principal: " , parentHandle) download = driver.find_element(By.XPATH, "/html/body/div/div/footer/md-toolbar/div/div/img") if download is not None: print("found") download.click() wait = WebDriverWait(driver, 10) pass = espera.until(EC.element_to_be_clickable((By.XPATH, "/html/body/div/div/footer/md- toolbar/div/div/img/../../../../../../../body[@class='layout-column md-dialog-is-showing']"))) if pass is not None: print("found") time.sleep(10) driver.quit()
I use Python, Selenium Web Driver and Chrome Browser
thanks who can have any ideas
Marcee last edited by
Your xpath locator is wrong , try the below xpath:
The errors were ,
- space after /html/body/div/div/footer/md-
- more than one space character after body[@class="layout-column
- 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
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.