0

I have the following code:

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait, Select
from selenium.webdriver.common.keys import Keys

if __name__ == '__main__':
    path_to_chromedriver = r'C:\chromedriver'  # change path as needed
    browser = webdriver.Chrome(executable_path=path_to_chromedriver)
    wait = WebDriverWait(browser, 10)
    browser.get("https://pjm.com/")
    wait.until(EC.presence_of_element_located((By.XPATH, "/html/body/form/div[3]/div/div[1]/div/div[1]/span[2]"))).click()
    wait.until(EC.presence_of_element_located((By.ID, "IDToken1"))).send_keys("user")
    wait.until(EC.presence_of_element_located((By.ID, "IDToken2"))).send_keys("pwd")

But the last two lines of codes are not able to execute and I don't have a clue why it should be like that.

1 Answer 1

1

I see that the click() will open a new tab, in which case you have to switch to that tab before proceeding with login details:

browser.switch_to.window(browser.window_handles[1])
wait.until(EC.presence_of_element_located((By.ID, "IDToken1"))).send_keys("user")
wait.until(EC.presence_of_element_located((By.ID, "IDToken2"))).send_keys("pwd")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.