如何使用 Selenium Python 在 https://www.tempinbox.xyz/mailbox/username@domain.name 中单击验证消息和按钮

How to click on the verification message and button within https://www.tempinbox.xyz/mailbox/username@domain.name using Selenium Python

我想通过单击按钮转到某个页面。首先我需要点击邮件,然后点击“这就是我”

time.sleep(10)
second_tab = webdriver.Chrome()
second_tab.get("https://www.tempinbox.xyz/mailbox/fohtek@fitschool.be")
clickmails= second_tab.find_element_by_xpath("//div[2]/div[2]/div/div[2]").click()
time.sleep(5)
clickverilink=second_tab.find_element_by_xpath("//a[contains(.,'This is me!')]").click()

但出于某种原因,每当我点击它时,它都会将我重定向到一个随机的广告页面。我哪里错了?

首先点击邮件项目,文本为激活您的 Wattpad 帐户,然后点击 这就是我!按钮你要诱导 for the element_to_be_clickable() and you can use either of the following :

  • 使用CSS_SELECTOR:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://www.tempinbox.xyz/mailbox/fohtek@fitschool.be")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#mails div.message"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "table.container#container table.row#row2 tbody td#maincontent a"))).click()
    
  • 使用XPATH:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://www.tempinbox.xyz/mailbox/fohtek@fitschool.be")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='mails']//div[@class='message']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='container' and @id='container']//table[@class='row' and @id='row2']//tbody//td[@id='maincontent']//a[contains(., 'This is me!')]"))).click()
    
  • 浏览器快照: