Data not capturing using Selenium web driver

I am trying to capture the product description from a webpage using ID and tagname but when I print it, it is showing blank. However I think I have used correct locators to locate the element.

Page Source

    <div id="item-description-block" class="layout-container layout-container-background clearfix">
<h2>About this item</h2>
<div id="social_share" class="details-row" onclick="javascript:clickPDP('Share','123070751499');">
<div class="details-row clear_both">
<div id="inspirational_copy">
<p>The big plus: Our new formula now helps strengthen skin's own moisture barrier. More moisture stays in. Skin feels soft, springy. Has a healthy-looking glow.</p>

Web Driver Code

WebElement description =driver.findElement("inspirational_copy").tagName("p"));
String description1 = description.getText();


I just tested it in Python and if you replace"inspirational_copy").tagName("p") with a valid css selector you can then use getText() to get the text you’re looking for.

WebElement description =driver.findElement(By.cssSelector("div[id='inspirational_copy']>p"));
String description1 = description.getText();

I did notice when I arrived on the page I got a welcome message. This message prevented me from getting the text. After closing it I could get the element and the text without problems.

WebElement close = driver.findElement(By.cssSelector("button[title='Close']");

Leave a Reply

Your email address will not be published. Required fields are marked *