英文:
Having issues finding an website element in Selenium
问题
I'm building a bookerbot for fun, and it's my first time using Selenium. I'm really stumped for why I keep getting the following error:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id=\"root\"]/main/section[2]/div/button"}
The sample website I'm trying this is a workout class site: https://www.barrys.com/my-account/
I'm simply trying to click on the login button, so using the following command:
WebDriverWait(driver, 5000).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/main/section[2]/div/button'))
).click()
driver.find_element(By.XPATH, '//*[@id="root"]/main/section[2]/div/button')
英文:
I'm building a bookerbot for fun, and it's my first time using Selenium. I'm really stumped for why I keep getting the following error:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="root"]/main/section[2]/div/button"}
The sample website I'm trying this is a workout class site: https://www.barrys.com/my-account/
I'm simply trying to click on the login button, so using the following command:
WebDriverWait(driver, 5000).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/main/section[2]/div/button'))
).click()
driver.find_element(By.XPATH, '//*[@id="root"]/main/section[2]/div/button')
答案1
得分: 0
There is an iframe
within which the Login button exists. So, before clicking on the login button, you need to switch into the iframe
, then perform the action. Try the below code:
iframe = driver.find_element(By.XPATH, '//iframe[1]')
driver.switch_to.frame(iframe)
WebDriverWait(driver, 5000).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/main/section[2]/div/button'))
).click()
英文:
There is an iframe
within which the <kbd>Login</kbd> button exist. So, before clicking on the login button, you need to switch into the iframe
, then perform the action. Try the below code:
iframe = driver.find_element(By.XPATH, '//iframe[1]')
driver.switch_to.frame(iframe)
WebDriverWait(driver, 5000).until(
EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/main/section[2]/div/button'))
).click()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论