![]() String mainPageURL = driver.getCurrentUrl() ("Title of main web page: " +getTitleOfMain) String getTitleOfMain = driver.getTitle() Now, switch to main web page from iframe by using defaultContent() method. Locate the first iframe and switch driver to first iframe by index value = 'query-input']")).sendKeys("Selenium = 'wpb_button wpb_btn-inverse btn']")).click() Int iFrameSize = driver.findElements(By.tagName("iframe")).size() Locate the total number of iframes on the web page. Wait for some time to load web page completely.ĭriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS) Call get() method and pass the URL as a parameter. Store the URL in a variable of type String. Create a driver object for Firefox browser. Program source code 1: package seleniumProject Now, it’s time to write WebDriver code to automate the above following scenario. At last, quite all web pages on the open web browser. Locate the web element “Register with us” on the second frame and click it. Again switch driver context to the second frame by its index value.ġ0. Get the title and current URL of the main web page.ĩ. Now, switch from the first frame to the main web page.Ĩ. After switching, locate the web element search box on the frame by By.xpath, send a text “Selenium Jobs” and then click on the search button.ħ. Locate and switch driver context to the first iframe by its index value.Ħ. Locate the total number of frames on the main web page.ĥ. Wait for some time to load the page completely.Ĥ. So, let’s see at a glance at the following scenarios.ģ. We will also handle switching between the frames of a web page. Let’s take a scenario where we will identify all the frames by their index value. ![]() Index value of the iframe starts with ‘0’ and goes on to 0,1, 2…įor example, suppose that there are 100 frames on the webpage, you can switch to iframe by using index value, as follows: driver.switchTo().frame(0) Switching to Frame by Index:Īn index is an attribute for the Iframe through which we can switch to it. Let’s understand all three ways one by one. Selenium WebDriver provides three ways to switch over the elements on an iframe. It takes an input parameter as WebElement of the frame. This is another overloaded version of the method. WebDriver frame( WebElement frameElement ): This method helps to switch to the frame if you are not sure about index of the target frame.ģ. It accepts the name of frame or its ID as an input parameter. This is the overloaded method of previous. WebDriver frame( String frameName or frameID ): If a web page contains four frames, WebDriver index them as 0, 1, 2, 3, and 4, where zero index is assigned to the first frame in the DOM.Ģ. This method accepts an input parameter as an index of frame that we want to switch to. There are three versions of syntax available in Webdriver for the frame. If you find any tag name with the ‘iframe’, it represents that the page consisting of an iframe. You can search by writing ‘iframe’ in it. Now you will see “search” option on the top bar. Right-click on the web page, click on the option ‘View Page Source’, and press ctrl+F. ![]() ![]() An example is shown in the below screenshot.Ģ. Right-click on the element and see an option like ‘ This Frame‘.
0 Comments
Leave a Reply. |