superabsorbent polymer
superabsorbent polymer

Reputation: 144

driver.get(url) does not work after some process

After I login a website, I can't navigate. And program does not throw an error. I suspect from switching the frame but could not manage to solve the problem.

            RedditBot.driver.get(self.targetUrl) #working
            
            RedditBot.driver.get("https://www.reddit.com/")
            
            login=RedditBot.driver.find_element_by_link_text("Log In")
            login.click()

            RedditBot.driver.switch_to_frame(RedditBot.driver.find_element_by_tag_name('iframe'))
            username_in = RedditBot.driver.find_element_by_xpath("//*[@id='loginUsername']")
            self.typing(username_in, "username")

            pass_in = RedditBot.driver.find_element_by_xpath("//*[@id='loginPassword']")
            self.typing(pass_in, "pass")

            pass_in.send_keys(Keys.ENTER)
            RedditBot.driver.switch_to_default_content()
            
            RedditBot.driver.get(self.targetUrl) #not working

Upvotes: 1

Views: 249

Answers (1)

cruisepandey
cruisepandey

Reputation: 29382

I used the below code with explicit wait to print the current URL :

Code :

driver = webdriver.Chrome(options = options)
driver.maximize_window()
driver.get("https://www.reddit.com/")
wait = WebDriverWait(driver, 10)
print(driver.current_url)
login = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href^='https://www.reddit.com/login/?']")))
login.click()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src*='login']")))
wait.until(EC.element_to_be_clickable((By.ID, "loginUsername"))).send_keys("your user name")
wait.until(EC.element_to_be_clickable((By.ID, "loginPassword"))).send_keys("your password")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[class^='AnimatedForm__submitButton']"))).click()
driver.switch_to.default_content()
wait.until(EC.element_to_be_clickable((By.ID, "header-search-bar"))).send_keys("Python" + Keys.RETURN)
sleep(5)
print(driver.current_url)

O/P :

https://www.reddit.com/
https://www.reddit.com/search/?q=Python

Process finished with exit code 0

Upvotes: 1

Related Questions