Take HTML source and add to log in Selenium IDE?

Hello All,

I am trying to find a way to save a specific part of the HTML source to the log, for example I have a drop down box and I would like to save all drop down values to the log. I have had some success with assertHtmlSource, but that gets the entire HTML source when I’m only really interested in specific sections.

The structure of the element in question is:

Any help would be greatly appreciated! :slight_smile:



Hello, below is an example which will hopefully help.

Assuming we had the following list of cars on a web page:
<select id="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select>

In C# with Selenium WebDriver you could find the element above by first finding the list (where Id=cars) and then get all available options in that list.

// Get a list of cars from the above select list var listOfCars = Driver.FindElement(By.Id("cars")).FindElements(By.XPath("option"));

// go through each option we found above foreach (IWebElement car in listOfCars) { Console.WriteLine(car.GetAttribute("text")); // print out text of element Console.WriteLine(car.GetAttribute("value")); // print out text of element }

Let me know if this did/didn’t work - happy to try and assist further :slight_smile:

I haven’t tried it with Selenium but in should be able to use javascript executor and send it:


where ‘cssSelector’ is a valid CSS selector. For example, on www.google.com.mx:

document.querySelector(’#body div>div’).innerHTML

will return something like:

"<style>#hplogo{background:url(/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png) no-repeat}@media (-webkit-max-device-pixel-ratio:1),(max-resolution:96dpi){#hplogo{background:url(/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png) no-repeat}}</style><div style="background-size:272px 92px;height:92px;width:272px" title="Google" align="left" id="hplogo" onload="window.lol&amp;&amp;lol()"><div class="logo-subtext">México</div></div>"