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,460 points
12,697 views

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,710 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,910 points
20,840 views
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,910 points
6,267 views
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, 2019 in Selenium by Anvi
• 14,150 points
6,544 views
0 votes
2 answers

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,500 points
13,735 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,172 views
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,910 points
7,249 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,888 views
+10 votes
17 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,360 points
198,171 views
+2 votes
3 answers

How can we handle authentication popup in Selenium WebDriver using Java

1) By passing user credentials in URL. String ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
29,122 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP