I get
File "login-registration.py", line 33, in drv.find_element(By.XPATH, '//*[@id="page-36"]/div/div[1]/nav/ul/li[6]/a')
selenium.common.exceptions.NoSuchFrameException: Message:
Here's my code
drv = webdriver.Safari()
url = 'http://practice.automationtesting.in/'
drv.get(url)
drv.find_element(By.XPATH, '//li[@id="menu-item-50"]').click()
time.sleep(3)
drv.find_element(By.XPATH, '//input[@id="username"]').send_keys(email)
drv.find_element(By.XPATH, '//input[@id="password"]').send_keys(paswrd)
drv.find_element(By.XPATH, '//input[@name="login"]').click()
wait(driver, 20).until(EC.url_to_be('https://practice.automationtesting.in/my-account/'))
locator = (By.XPATH, '//*[@id="page-36"]/div/div[1]/nav/ul/li[6]/a')
wait(drv, 30).until(EC.element_to_be_clickable(locator))
I thought it should wait for element and then send error message if it's not there, but i get error right after changing pages. Neither wait url_to_be
nor wait element_to_be_clickable
seems to be doing anything.
CodePudding user response:
Try this code:
url = 'http://practice.automationtesting.in/'
drv.get(url)
drv.find_element(By.XPATH, '//li[@id="menu-item-50"]').click()
# time.sleep(3)
drv.find_element(By.XPATH, '//input[@id="username"]').send_keys("email")
drv.find_element(By.XPATH, '//input[@id="password"]').send_keys("pwd")
drv.find_element(By.XPATH, '//input[@name="login"]').click()
locator = (By.XPATH, '//*[@id="page-36"]/div/div[1]/nav/ul/li[6]/a')
WebDriverWait(drv, 30).until(EC.element_to_be_clickable(locator)).click()
I am assuming your scenario is - logging in and logout, in that case, I am not sure why you are using the below line, its not needed:
wait(driver, 20).until(EC.url_to_be('https://practice.automationtesting.in/my-account/'))
CodePudding user response:
Try:
drv = webdriver.Chrome()
url = 'http://practice.automationtesting.in/'
drv.get(url)
drv.maximize_window()
drv.find_element(By.XPATH, '//li[@id="menu-item-50"]').click()
WebDriverWait(drv, 10).until(EC.presence_of_element_located((By.XPATH, '//input[@id="username"]'))).send_keys("[email protected]")
WebDriverWait(drv, 10).until(EC.presence_of_element_located((By.XPATH, '//input[@id="password"]'))).send_keys("Automation2022!!")
drv.find_element(By.XPATH, '//input[@name="login"]').click()
WebDriverWait(drv, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="page-36"]/div/div[1]/nav/ul/li[6]/a'))).click()
As you can see I changed your line: drv.find_element(By.XPATH, '//*[@id="page-36"]/div/div[1]/nav/ul/li[6]/a')
by WebDriverWait(drv, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="page-36"]/div/div[1]/nav/ul/li[6]/a')))
. Why? Because once you click on login your page will change so you need to wait for the next element, if you do drv.find_element(By.XPATH, '//*[@id="page-36"]/div/div[1]/nav/ul/li[6]/a')
you are not waiting for that element and your driver will not find it and it will fail with the error you are getting.