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

102 Views Asked by At

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

1

There are 1 best solutions below

2
chris-crush-code On BEST ANSWER

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.