I tried to declare webdriverwait as globally across all the files. Here are my Python files below for your reference.
file1 loginpage.py
import time
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(90)
class LoginPage():
def __init__(self, driver):
self.driver = driver
self.username_textbox = "txtUsername"
self.password_textbox = "txtPassword"
self.login_button = "btnLogin"
def enter_username(self, username):
if not self.username_textbox.isspace():
print("User Name textbox in not empty", self.username_textbox.isspace())
time.sleep(2)
self.driver.find_element_by_id(self.username_textbox).clear()
self.driver.find_element_by_id(self.username_textbox).send_keys(username)
def enter_password(self, password):
if not self.password_textbox.isspace():
print("Passwrod textbox is not empty", self.password_textbox.isspace())
time.sleep(2)
self.driver.find_element_by_id(self.password_textbox).clear()
self.driver.find_element_by_id(self.password_textbox).send_keys(password)
def click_login(self):
self.driver.find_element_by_id(self.login_button).click()
print("User Login Successful")
file2 homepage.py
from selenium import webdriver
from com.qa.pomdemo.browsersetup.browserActions import Browser
from com.qa.pomdemo.pages import loginPage
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
# from selenium.webdriver.support.ui import WebDriverWait
class HomePage():
def __init__(self, driver):
self.driver = driver
# self.wait = WebDriverWait(self.driver, 90)
self.welcome_admin_link = "//a[@id='welcome']"
self.logout_link = "//div[@id='welcome-menu']//a[contains(text(), 'Logout')]"
self.header_leave_link = "//a[@id='menu_leave_viewLeaveModule']"
def click_welcome_admin_link(self):
print("The title of the current page is: " +self.driver.title)
self.driver.back()
print("The title of the current page is: " +self.driver.current_url)
self.driver.forward()
print("The title of the current page is: " +self.driver.current_url)
# wait = WebDriverWait(self.driver, 90)
element_welcome_admin_link = loginPage.wait.until(EC.element_to_be_clickable((By.XPATH, self.welcome_admin_link)))
element_welcome_admin_link.click()
print("Welcome Successful")
def click_header_leave_link(self):
element_header_leave_link = loginPage.wait.until(EC.element_to_be_clickable((By.XPATH, self.header_leave_link)))
element_header_leave_link.click()
print("Leave header link clicked")
def click_logout_link(self):
logout_element = loginPage.wait.until(EC.element_to_be_clickable((By.XPATH, self.logout_link)))
logout_element.click()
print("Logout Successful")
question from:
https://stackoverflow.com/questions/65951765/i-tried-to-declare-webdriverwait-as-globally-across-all-the-files 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…