Selenium 2 - Switching focus to a frame that has no name/id

后端 未结 5 2011
轻奢々
轻奢々 2021-01-02 12:13

So right now I\'m trying to figure out how I can switch focus to a frame in Selenium 2 when the frame has no name or id? For a named frame I do:

driver.Switc         


        
5条回答
  •  太阳男子
    2021-01-02 12:26

    You can just give the id of your iframe instead of iframe-name.

    Please see my below example, it worked for me.
    In the example I am switching to one iframe in my page and clicking on the element in that iframe, which is "worksheet0" .

    Use the code :

    driver.switchTo().frame("topframe");    
        WebElement worksheet0 = driver.findElement(By.xpath("//*@id='reportSelect:Worksheet_lbl']"));               worksheet0.click();             
    

    The HTMLof the iframe :

      < iframe id="topframe" height="83px" frameborder="0" width="100%" scrolling="NO" '1331808552380'"="" +="" src="initialize.do?init=header&cacheBuster=" name="topframe" marginheight="0" marginwidth="0">
    

提交回复
热议问题