Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Selenium return to previous page after driver.get #14494

Closed
hkpmatt opened this issue Sep 12, 2024 · 5 comments
Closed

[🐛 Bug]: Selenium return to previous page after driver.get #14494

hkpmatt opened this issue Sep 12, 2024 · 5 comments
Labels
I-question Applied to questions. Issues should be closed and send the user to community resources.

Comments

@hkpmatt
Copy link

hkpmatt commented Sep 12, 2024

What happened?

I try to automate a court booking procedure and when I have automated the login action.
I try to navigate the driver to a new site that will help me to go to the booking site.
It can get to the desired URL if there is no more action after driver.get(URL) and yet,
When I add action to click the button after driver.get(URL) the script will return to the login page after driver.get(URL) and the address bar poped up the URL and right back to login page.

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.edge.options import Options
import undetected_chromedriver as uc
from undetected_chromedriver import Chrome, ChromeOptions
from selenium.webdriver.support import expected_conditions as EC

import os 
from dotenv import load_dotenv
import time
load_dotenv()
username = os.getenv('UNAME')
password = os.getenv('PASSWORD')
venue = "venue"
bookdate = '2024-09-12'
booktime = '2000'
sport = "basketball"
#print(username,password)
options = Options()
options.page_load_strategy = 'none'
options.add_argument('--disable-notifications')
options.add_argument('--incognito')
options.add_argument("--start-maximized")

options.add_experimental_option("detach", True)

driver = webdriver.Chrome(options=options)
def span_click(driver, xpath):
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, xpath))).click()

def span_keys(driver, xpath, value):
    WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, xpath))).send_keys(value)
    


driver.get("https://www.bookingsite.com")

#click login
span_click(driver,"//a[@class='btn btn--primary btn--grad btn--grad-org-outline']")

time.sleep(2)

#new tab after clicking login button
driver.switch_to.window(driver.window_handles[1])

#enter username, password and click login button
span_keys(driver,"//input[@name='pc-login-username']",username)
span_keys(driver,"//input[@name='pc-login-password']",password)
span_click(driver,"//div[@name='pc-login-btn']")
#time.sleep(1)

#try to wait for element appear after logged in
try:
    WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//ul[@class='el-menu-demo  el-menu--horizontal el-menu']")))
except Exception as e:
    print(f"An error occurred: {e}")

#get to the booking detail page
search_url = f"https://www.bookingsite.com/facilities/search-result?keywords={venue}&district=&startDate={bookdate}&typeCode=BASC&venueCode=291&sportCode=BAGM&typeName={sport}&frmFilterType=&venueSportCode=BAGM&isFree=false"

driver.get(search_url)

#When I add the below step, the browser cannot get to the booking detail page, but it can if i remove the belows
span_click(driver,"//div[@class='facility-search-box']//div[@class='text' and contains(span, 'search sport、venue')]")
span_keys(driver,"//div[@class='search-associate-input-box']//input",venue)

Relevant log output

[29036:37044:0913/111029.233:ERROR:interface_endpoint_client.cc(722)] Message 2 rejected by interface blink.mojom.Widget

Operating System

Windows 10

Selenium version

4.24.0

What are the browser(s) and version(s) where you see this issue?

Chrome

What are the browser driver(s) and version(s) where you see this issue?

Chrome Driver 128.0.6613.120

Are you using Selenium Grid?

No response

Copy link

@hkpmatt, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@shbenzer
Copy link
Contributor

span_keys and span_click are not functions implemented in native Selenium - are these functions you defined locally?

@hkpmatt
Copy link
Author

hkpmatt commented Oct 15, 2024 via email

@hkpmatt
Copy link
Author

hkpmatt commented Oct 16, 2024

Incase you all want to know, the booking site is https://www.smartplay.lcsd.gov.hk/website/tc/index.html

@diemol diemol added I-question Applied to questions. Issues should be closed and send the user to community resources. and removed I-defect needs-triaging labels Nov 5, 2024
Copy link

github-actions bot commented Nov 5, 2024

💬 Please ask questions at:

@github-actions github-actions bot closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-question Applied to questions. Issues should be closed and send the user to community resources.
Projects
None yet
Development

No branches or pull requests

3 participants