Selenium frame (WebElement) –
Many applications contain an unnoticeable frame or iframe which requires a switch before executing the next statement. With Selenium, we can use 3 methods to switch to a frame. The methods are frame (WebElement), frame (String), and frame (index). Watch the following video which shows how to switch to a frame using frame (WebElement).
► View All Videos On LinkedIn = [ Ссылка ]
► View All Videos On YouTube (Caption or Non-Caption) = [ Ссылка ]
► View All Videos On Facebook (Caption or Non-Caption) = [ Ссылка ]
► Download Transcript, Presentation, and Source Code = [ Ссылка ]
► View Transcript, Presentation, and Source Code via github = [ Ссылка ]
► Free Selenium PDF Book: [ Ссылка ]
► Free Java PDF Book: [ Ссылка ]
► All Paperback & eBooks: [ Ссылка ]
► Increase Video Quality: Settings - Quality - Select HD
► CC Font Size: Settings - Subtitles/CC - Options - Font Size
► Turn CC On or Off: Click CC
► Transcript
Let’s walkthrough our Application Under Test [ Ссылка ] . First, we load the application then click the Log In/Sign Up hyperlink. Next, we click the link at the bottom “Login/Signup with mobile number and password”. Finally, we enter our number or email.
This Test Script will Fail and throw an exception if we do not switch to a frame but which step requires a switch. We are going to switch after clicking the Log In/Sign Up hyperlink.
Let’s go to Eclipse and create our Automation Test Script. We setup our Test with System.setProperty on Chrome using driver = new ChromeDriver(); then maximize the window driver.manage().window().maximize;
The Test method is switchToFrames. Now load the AUT. driver.get, [ Ссылка ] . Add a dynamic Wait statement. This here is an Explicit Wait Statement for 5 seconds. Why add a wait statement?
We are going wait until 24x7 Help shows up. I am going to reload the page and you will see how we wait until 24x7 Help and these other elements show up. Finish the wait statement. You can watch video number 22 to see the benefits of an Explicit Wait. Now we click the Log In/Sign Up hyperlink. driver.findElement By xpath dot click. The xpath value will contain text for Log In/Sign Up then wait for this dialog to load. We are going to wait for the bottom hyperlink because that’s the link we will click.
This is a customized xpath value for Log In/Sign Up. I will create a video explaining how to create customized xpath values. We add the wait statement then click the hyperlink at the bottom.
Last, we enter the phone number or email. driver.findElement By id dot sendKeys Get the value for id Inspect the element. We see the value for id is input_0 send (123) 456-7890.
Let’s Run.
Nothing happens after clicking the Log In/Sign Up hyperlink. Our test failed.
Let’s go back to our AUT and see why it failed. Right click and we see View Frame Source. That means this dialog is a frame or an iframe. It is like the example from our Introduction when looking at frames in W3 Schools. Notice the difference when I right click outside the iframe. We do not see View Frame Source. That lets us know we must switch before performing a command.
Go back to Eclipse and switch to frame. driver.switchTo. The description states “Sends future commands to a different frame or window”. In this intellisense, we see different methods for switching to a frame or window. We are going to switch to a frame.
Here’s the frame methods, we reviewed in our introduction. frame(index) selects a frame by it’s zero based index. frame(String) selects a frame by its name or ID. frame(WebElement) selects a frame using it’s element. Select frame.
Now, let’s inspect an element within the iframe dialog. We are going to inspect the bottom link. The blue highlighted part is the link but let’s scroll up to the iframe tag. This iframe tag has an src attribute that contains login. CTRL + F to find the value. Let’s write our customized xpath value.
2 forward slashes
Iframe
Opening and Closing brackets
contains
Opening and Closing parenthesis
At symbol
src which is the attribute name
comma
2 single quotes
login is written inside the single quotes
The yellow highlight indicates we have located the iframe.
Copy the value
Now, let’s switch to the iframe. driver dot findElement By xpath then paste the value.
Let’s Run. We see phone number (123) 456-7890.
#SeleniumTraining #SeleniumAutomation #BeginnerSeleniumTutorials #SeleniumWebDriver
Ещё видео!