Try it out and let me know your finding in comments. When we type alert followed by a dot(.), your code editor will suggest some more options. Looks like it has only three methods to remember? Read the text of Alert window String strAlertText = alert.getText() alertText = alert.text Accept an Alert (click on OK/Yes) alert.accept() alert.accept() Dismiss an Alert (click on Cancel/No) alert.dismiss() alert.dismiss() Now we have an Alert object, we can perform actions on it. You need to import package for the Alert interface. To perform any action on this alert window, WebDriver first, needs to switch to it. tProperty("", "C:\\teachmeselenium\\chromedriver.exe") ĭriver.get("") from selenium import webdriverĬhrome_driver_path = "C:\teachmeselenium\chromedriver.exe"ĭriver = webdriver.Chrome(chrome_driver_path)Ĭlick on the link – Click Me to get Alert driver.findElement(By.linkText("Click Me to get Alert")).click() driver.find_element_by_link_text("Click Me to get Alert").click()Īs this statement is executed, the browser will prompt an alert as displayed in the above screenshot. Launch the browser and navigate to the Automation Practice page. To handle these type of scenarios WebDriver has given Alerts interface. This popup window is not part of the web page so normal Selenium code won’t be able to perform any action on it. When you’ll click on the link – ‘Click Me to get Alert’, the page will prompt this alert: You can check it out yourself by going to the Automation Practice page. Some of them display text like this – “Are you sure you want to perform this action?”. You must have noticed that on clicking some links/buttons, the page displays an alert window that asks the user to confirm if she or he wants to do this action by clicking on OK/Cancel or Yes/No buttons. In this tutorial, we will learn how to handle Alert windows. In the Previous Tutorial, we learned how to handle timeout issues in Selenium. Automation Practice | First Selenium Script.Understanding var, let and const in JavaScript.Prototypes in JavaScript | JavaScript
0 Comments
Leave a Reply. |