I wanted to go to a page by clicking a button. First i needed to click on the mail, and then click on "this is me"
time.sleep(10)
second_tab = webdriver.Chrome()
second_tab.get("https://www.tempinbox.xyz/mailbox/[email protected]")
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()
But for some reason, whenever I click this, it redirects me to a random ad page. Where am i wrong?
To click first on the on the mail-item with text as Activate your Wattpad account and then to click on This is me! button you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
Using 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/[email protected]")
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()
Using 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/[email protected]")
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()
Browser Snapshot:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With