简体   繁体   中英

Selenium XPATH not finding element

I am trying to find an element with xpath but it is not working.

import string
import random

import os


from random_word import RandomWords

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

driver.get("https://yopmail.com/en/")
driver.find_element(By.NAME, 'login').send_keys('grudsimcobottest')
driver.find_element(By.NAME, 'login').submit()

try:
    elem = WebDriverWait(driver, 60).until(
    EC.presence_of_element_located((By.XPATH, '//div[text()="Confirm account deletion"]'))
    )
finally:
    a = 1
    
confirm_email = driver.find_element(By.XPATH, '//div[text()="Confirm account deletion"]')
confirm_email.click


try:
    elem = WebDriverWait(driver, 60).until(
    EC.presence_of_element_located((By.XPATH, '//a[text()="Delete"]'))
    )
finally:
    a = 1

delete_button_in_email = driver.find_element(By.XPATH, '//a[text()="Delete"]')
delete_button_in_email.click()

This is the code^

Traceback (most recent call last):
  File "C:\Users\notgr\Desktop\Everything\SC ahks\python\yopmailmakendelete.py", line 28, in <module>
    elem = WebDriverWait(driver, 60).until(
  File "C:\Users\notgr\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\support\wait.py", line 90, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

This is the error^

the website

If you go to yopmail.com and type in grudsimcobottest you can see it live if you like. I'm not sure why the div highlighted isn't being selected and clicked, it times out when looking for it. Help much appreciated.

<iframe frameborder="0" width="100%" height="100%" src="" name="ifinbox" onload="onloadifinbox()" id="ifinbox" state="full"></iframe>

Your element is in an iframe switch to it prior to finding the element.

WebDriverWait(driver, 60).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"ifinbox")))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM