Search code examples
xpathfirebugfirepath

How to write Xpath for webelement which are on iframe using firebug/Firepath?


enter image description here

  1. I can write Xpath with or without Firebug/ Firepath but it would be great if there is work around to write Xpath with iframe using these third party tool.

  2. First I need to move to iframe then write regular Xpath for webElements


Solution

  • use xpath to find the iframe. then use getattribute() to get the src. then navigate to the src.

    for example:

    var myFrame = driver.FindElement("descendant::iframe[@name='TheIFrame']");
    string frameSrc = myFrame.GetAttribute("src");
    driver.Navigate().GoToUrl(frameSrc);
    //now you're on the frame and interact with its DOM
    

    If you don't want to navigate away from the page you're on, you have a few otions:

    1) Create a new driver and navigate there

    2) use httpclient (less overhead than the driver) to get the content by sending a get to the src url, then use HTMLAgilityPack to load it into an HTMLDoc you can navigate with XPath - of course this will let you scrape data but you won't be able to click buttons or interact with javascript.