Would Like To Understand Why Switch_to_alert() Is Receiving A Strikethrough And How To Fix
I'm trying to 'accept' a simple modal alert (an onscreen popup with only OK button) but switch_to_alert() in driver.switch_to_alert() is receiving a strikethrough (on pycharm). I'
Solution 1:
A couple of points:
switch_to_alert()
has been deprecated so you should useswitch_to().alert
instead. You can find a relevant discussion in Python click button on alert.As per best practices, while switching to an alert, you need to use
WebDriverWait
withexpected_conditions
clause set to alert_is_present as follows:WebDriverWait(driver, 5).until(EC.alert_is_present).accept()
You can find a relevant discussion in Why switching to alert through selenium is not stable?
Solution 2:
Following the advice from @DebanjanB
, I have changed my code with the following (i only include the code you need for context).
However, I get the following error:
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None
Message: Dismissed user prompt dialog: Useror Password isnot valid
One other comment to make when using Pycharm. When you see the word "alert" in in the code it is highlighted in yellow. Pycharm advises Statement seems to have no effect Inspection info: This inspection detects statements without any effect. I'm not sure what this means.
from selenium import webdriver
from selenium.webdriver.common.by import By # **This is greyed out in pycharm. is this** correct?from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
deftest_login_valid(self):
driver = self.driver
driver.get('http://www.demo.guru99.com/V4/')
login = LoginPage(driver)
for r inrange(2, rows + 1):
#inserts username and password from spreadsheet - if username/password does not login the else condition is called and alter is raised. I'm trying to close this popup alert.if driver.title == "Guru99 Bank Manager HomePage":
print("test is passed")
spreadsheet.writeData(path, "Sheet1", r, 3, "test passed")
driver.get('http://www.demo.guru99.com/V4/')
else:
print("test failed")
spreadsheet.writeData(path, "Sheet1", r, 3, "test failed")
# This line should close the alert but appears to cause error
**WebDriverWait(driver, 300).until(EC.alert_is_present).accept**
Post a Comment for "Would Like To Understand Why Switch_to_alert() Is Receiving A Strikethrough And How To Fix"