How to find element using classname and tagname using selenium webdriver?

0 votes

I wrote the below selenium code to find the description which include classes and tagname but it is throwing an error. Please suggest the solution for this

WebElement WWdescription = driver.findElement(By.className("atb-delivery-accordions").className("section highlight-01").tagName("p"));    

<div class="atb-delivery-accordions">

    <div class="page-accordion opened">

    <input id="moreDetails-acc" class="acc-check" type="checkbox" checked="">

    <label class="acc-label opened" data-panel-id="moreDetailsAcc" for="moreDetails-acc">Description</label>

    <div class="content" data-panel-id="moreDetailsAcc" style="display: block;">

    <div class="information-panel">

    <div class="subcontent">

    <div class="section highlight-01">

    <p>A pretty floral lace collection combining contrast bows and trims for a feminine on trend look. The fuller coverage of our post surgery bras provide support, comfort and confidence. The dual cotton pockets are perfect for a prosthesis. Combine style and value with this pack of 2 bras.</p>
Apr 17, 2018 in Selenium by Meci Matt
• 9,420 points

1 answer to this question.

0 votes

Use the below code or you can take reference from it:

 WebElement parentEle = driver.findElement(By.xpath("//div[@class='atb-delivery-accordions']"));

 WebElement descriptionEle = parentEle.findElement(By.tagName("p"));

  String descriptionText = descriptionEle.getText();
answered Apr 17, 2018 by king_kenny
• 3,650 points
if class name not found how to check class name is exist or not

You can go to inspect and then hover the cursor to the web element to check the class name and if there is no class name then you can use XPath as the last resort. 

See this, 

See here, in inspect section you can see the class name and all and using chropath you can see the xpath for the element.

Hope this helps.

Related Questions In Selenium

0 votes
1 answer

How to get next sibling element using XPath and Selenium for Java?

Below code will help you: Try following-sibling axis : WebElement ...READ MORE

answered May 15, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer

How to set Page Load Timeout using C# and Selenium Webdriver

Check this out C# WebDriver API now contains ...READ MORE

answered Aug 3, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer
0 votes
1 answer

How to mouse hover on a web element using Selenium WebDriver?

Hello Nitin, to automate mouse hovering over ...READ MORE

answered May 7 in Selenium by Anvi
• 13,400 points
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
+9 votes
14 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,250 points
+2 votes
1 answer

How can we handle authentication popup in Selenium WebDriver using Java

The Alert Method, authenticateUsing() lets us skip ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,650 points