Iframe problem switching - Java + Selenium

Reprinted URL: https://blog.csdn.net/u011541946/article/details/73695239

 

 

What is the frame, simply, is to a web page is divided into several sub-pages, the brain make this such a page.

I put a blank html file, using the frame technology, is divided into two pages, the left shows the Baidu home page, on the right display Google home page.

This is a simple to use frame.

 

webdriver default look of elements are Top window of this layer, if some elements embedded within the frame, you need to switch to the use of statements switch to the internal frame,

Then go to an operating element after the operation is over, the need to switch out default region, i.e. Top window.

 

 

====================================================================================================

 

 

 

The first is to locate the index frame, that is, if a plurality of page frame, can, frame (2) from downward to locate The frame (1).

The second is the way we are introducing today, is based on the frame of the ID or name to identify.

The third element is to identify in accordance with an interior of the frame.

The fourth is to switch from the inside to the default Top Window frame method.

 

 

==============================================================================================

 

 

package lessons;
 
import java.util.concurrent.TimeUnit;
 
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
 
public class ElementOpration {
    public static void main(String[] args) throws Exception {  
        
        System.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe");  
           
        WebDriver driver = new ChromeDriver();  
     
        driver.manage().window().maximize();  
       
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
          
        driver.get("http://data.pharmacodia.com/web/homePage/index?ns=1&ts=1&str=YWSJ");  
       
        Thread.sleep ( 1000 );
         // switch to a frame inside a 
        driver.switchTo () frame ( "rightMain." );
         // chemical drugs in this category click 
        WebElement drug_type_huaxue = driver.findElement (By.xpath ( " // * / span [@ title = 'chemical drugs'] " ));
        drug_type_huaxue.click();
        Thread.sleep ( 1000 );
         // switch to Top Windows, click the Permissions tips above to go to the login button. 
        driver.switchTo () defaultContent ().;
        
        driver.findElement(By.xpath("//*[@id='noLoginAlert']/div/button")).click();
        
    }  
}

 

 

Explain the above test, open a page, then use swithcTo method, by the name of frame for rightMain, switching into the internal frame from Top Window, and then went to look for chemical drugs that element, and then to click.

 

In no authority pop in to the landing of this element is an element Top Window layer, so before you click, you need to switch out in rightMain this frame, switch to Top Window layer in order to find the correct log on to this element.


Web page using frame technology is still relatively rare, I saw General Electric's Web site have no frame, if there are flash Baidu ad networks, internal frame no actual operational elements. So, if you encounter after you are sure your positioning element expression is not wrong, but still pack No such abnormal element of whether to use the technology under the frame you have to consider, if so, the manner demonstrated in this article to deal with just fine.

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12216310.html