Via that code i have extracted all desired text out of a html document
private void RunThroughSearch(string url) { private IWebDriver driver; driver = new FirefoxDriver(); INavigation nav = driver.Navigate(); nav.GoToUrl(url); var div = driver.FindElement(By.Id("results")); var element = driver.FindElements(By.ClassName("sa_wr")); }
though as i need to refine results of extracted document
Container HEADER -> Title of a given block Url -> Link to the relevant block text -> body of a given block /Container
as u can see in my code i am able to get the value of the text part as a text value , that was fine, but what if i want to have the value of the container as HTML and not the extracted text ?
<div class="container"> <div class="Header"> Title...</div> <div class="Url"> www.example.co.il</div> <div class="ResConent"> bla.. </div> </div>
so the container is about 10 times in a page i need to extract it's innerHtml .
any ideas ? (using Selenium)
Open Firefox browser with the URL: SoftwareTestingHelp.com. Using text method of selenium web driver, find the web element with text – Write and Earn. Validate if the selected element is displayed on the web page. If it is displayed, print the text as Element found using text.
The getText() method simply returns the visible text present between the start and end tags (which is not hidden by CSS). The getAttribute() method on the other hand identifies and fetches the key-value pairs of attributes within the HTML tags.
We can get the entered text from a textbox in Selenium webdriver. To obtain the value attribute of an element in the html document, we have to use the getAttribute() method. Then the value is passed as a parameter to the method.
This seemed to work for me, and is less code:
var element = driver.FindElement(By.ClassName("sa_wr")); var innerHtml = element.GetAttribute("innerHTML");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With