How to handle frame, alert and dropdown in Java (Selenium: WebDriver)
ฝัง
- เผยแพร่เมื่อ 2 ต.ค. 2024
- To handle frames in Selenium, Following methods are used −
switchTo().frame( frameNumber) : This method uses the frame id as the parameter. The index of frame id starts from 0. NoSuchFrameException is thrown if the frame is not found.
switchTo().frame( frameName) : This method uses the frame name as defined by the developer as the parameter. The frame name is considered a String and is enclosed in quotes. NoSuchFrameException is thrown if the frame is not found.
switchTo().frame( WebElement) : This method uses the webelement as the parameter.
NoSuchFrameException is thrown if the frame is not found.
StaleElementReferenceException if the frame is no longer active.
****** To handle Alert in Selenium ******
Void dismiss(): This method is used when ‘Cancel’ button is clicked in the alert box.
driver.switchTo().alert().dismiss();
Void accept(): This method is used to click on the ‘OK’ button of the alert.
driver.switchTo().alert().accept();
String getText(): This method is used to capture the alert message.
driver.switchTo().alert().getText();
Void sendKeys(String stringToSend): This method is used to send data to the alert box.
driver.switchTo().alert().sendKeys("Text");
***** To handle Drop-down in Selenium *****
To handle drop down and multi select list using Selenium WebDriver, we need to use Select class.
Types of Select Methods:
selectByVisibleText Method
selectByIndex Method
selectByValue Method
Types of DeSelect Methods:
deselectByVisibleText Method
deselectByIndex Method
deselectByValue Method
deselectAll Method
Please subscribe the channel and visit to www.ananyatech.net & write at info@ananyatech.net for more details.
Facebook page: / ananyasoftwaretechnolo...