I need to verify whether specific slot on webpage is loaded or not. I am using Selenium WebDriver in main() function for that (should I use a JUnit test case?).
What are ways to retrieve text between any <div> having a specific id?
If given this page:
<div id="center-2" class="promo">
<div class="unified_widget rcmBody">
<span class="logo"><img src="someimage.gif" /></span>
<span class="headline">Make money by Selling items on Amazon</span>
<span class="link"><a href="/content/sell-on-amazon.htm">Selling On Amazon</a></span>
<span class="body">Sell your items on Amazon.com. Amazon can help you grow your business and reach more customers.</span>
<div class="h_rule"></div>
</div>
</div>
when <div id = center-2> is given, I need to extract
“Make money by Selling items on Amazon”,
“Selling On Amazon”,
“Sell your items on Amazon.com. Amazon can help you grow your business and reach more customers.”
Which method should I use?
To be sure an element is loaded, use Implicit and Explicit waits.
Usually, when you need to interact with the element, an implicit wait is enough. Once it’s set, it’s used for every element lookup. In my experience, it’s enough for 95 % of cases.
If you need some more advanced waiting (or just use the wait once), explicit wait is there for you.
There are three usually used ways to retrieve an element with a specific
idI know about:The preferred way:
A good way if you need to begin with an element and then search its descendants:
The way a lot of people uses, because they’re comfortable with XPath:
To know more about CSS selectors and XPath, see any tutorial on the web.
About the text:
outputs
If you want to get the three things independently, use e.g.: