How to navigate a subframe inside a frameset using Selenium WebDriver?

前端 未结 4 2167
梦谈多话
梦谈多话 2020-11-28 14:41

I need to get the result from the table \"td\". But before I can do that I need to navigate a frame that contains it. The frame is one of the frameset elements that belongs

相关标签:
4条回答
  • 2020-11-28 15:14

    Through chaining methods together, once you switchTo().defaultContent, you can create temporary lists of available frames through findElements() by tagName and go to that specific frames' index...

    For example

    driver.switchTo()defaultContent();
    driver.switchTo().frame(driver.findElement(By.tagName("frameset")).findElements(By.tagName("frame")).get(2));
    
    0 讨论(0)
  • 2020-11-28 15:20

    Find the index of main frame starting from zero then use

    driver.switchTo.frame(mainFrameindex);
    

    Then find the index of sub frame in the main frame

    driver.switchTo.frame(subFrameIndex);
    

    You cannot directly switch to a child frame without first switching to the parent frame. This is how it works.

    0 讨论(0)
  • 2020-11-28 15:23

    I agree, you cannot directly switch to a child frame. Also, make sure to switch to the defaultContent (driver.switchTo.defaultContent) every time you want to switch frame. With regard to your example, driver.switchTo().frame("mainFrame.0.child") --- this could also work, but you need to get rid of unnecessary quotation marks.

    0 讨论(0)
  • 2020-11-28 15:32

    You can switch directly to the frame you want with the xPath. Get the Xpath through the Developer console, then:

    driver.switch_to.frame(driver.find_element_by_xpath('html / frameset / frameset / frame[1]'))

    0 讨论(0)
提交回复
热议问题