I have code (python / selenium):
# Alert start
WebDriverWait(self.driver, 5).until(EC.alert_is_present())
self.driver.switch_to_alert().dismiss()
# Alert end
The first row wait for alert in the browser and second row press "Cancel" button to dismiss this window. It works fine. I decided to create 2 functions.
def alertIsPresent(self, timeout=10):
WebDriverWait(self.driver, timeout).until(EC.alert_is_present())
def alertDismiss(self):
alert = self.driver.switch_to_alert()
alert.dismiss()
And I call this functions:
PageObject.alertIsPresent()
PageObject.alertDismiss()
The last ")" is underlined because "parameter self unfilled"... I'm newest in python, can you give me suggestion?
pageObjectClass:
class PageObject:
def __init__(self, driver, xpathLocator):
self.driver = driver
self.locator = xpathLocator
self.wait = WebDriverWait(self.driver, 100)
def waitElementToBePresent(self, timeout=10):
WebDriverWait(self.driver, timeout).until(
EC.visibility_of_element_located((By.XPATH, self.locator)))
def elementIsPresent(self):
return EC.visibility_of_element_located((By.XPATH, self.locator))
def alertIsPresent(self, timeout=10):
WebDriverWait(self.driver, timeout).until(EC.alert_is_present())
def alertDismiss(self):
alert = self.driver.switch_to_alert()
alert.dismiss()