0

I need to automate a procedure with selenium on the website Plus500, but I can't even get to log in. I just get the TimeoutException without being able to locate the part of the page where I need to enter my credentials. This is the code that I'm using for the log in but I fear the problem is a more general one. Does anyone know why is this happening?

driver.execute_script("window.open('https://app.plus500.com/trade?refurl=https%3A%2F%2Fwww.google.com%2F&innerTags=_cc_%20exp_new_sas_c&webvisitid=2a3139bc-78f7-4f48-a50d-c79e7b3e7abd&page=login&_ga=2.24870842.1255829517.1590833562-259196075.1590833562', 'new window')")
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
        (By.XPATH,'//*[@id="email"]'))).send_keys('myemail')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
        (By.XPATH,'//*[@id="password"]'))).send_keys('mypassword') 
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
        (By.XPATH, '//*[@id="submitLogin"]'))).click()

1 Answers1

1

You need to tell selenium which tab it should consider active, opening a new tab does not change the active tab in selenium's perspective. There are multiple options to achieve this, like described in this answer.

Basically you need to add this extra line after opening a new tab: driver.switch_to.window(driver.window_handles[-1]) and selenium will know that you want it to execute commands on the last tab in the browser.

So the fixed code is:

driver.execute_script("window.open('https://app.plus500.com/trade?refurl=https%3A%2F%2Fwww.google.com%2F&innerTags=_cc_%20exp_new_sas_c&webvisitid=2a3139bc-78f7-4f48-a50d-c79e7b3e7abd&page=login&_ga=2.24870842.1255829517.1590833562-259196075.1590833562', 'new window')")
driver.switch_to.window(driver.window_handles[-1])
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
        (By.XPATH,'//*[@id="email"]'))).send_keys('myemail')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
        (By.XPATH,'//*[@id="password"]'))).send_keys('mypassword') 
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
        (By.XPATH, '//*[@id="submitLogin"]'))).click()
Trapli
  • 1,517
  • 2
  • 13
  • 19