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.
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