You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
`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 = ChromeOptions()
options.page_load_strategy = 'none'
options.add_argument('--disable-notifications')
options.add_argument('--incognito')
options.add_argument("--start-maximized")
#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}")
#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)`
The text was updated successfully, but these errors were encountered:
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.
`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 = ChromeOptions()
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 = Chrome(use_subprocess=True, 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)`
The text was updated successfully, but these errors were encountered: