How to work with blocks in Selenium

0 votes
Hello members of the forum. I had such a question about Selenium in python, I only recently started trying to work with it, so I don't know much yet and I haven't found the answer on other sites! How to work with a list of blocks in Selenium? For example, let's take a friends page on Facebook, where each friend is highlighted as a separate block with same class, so I want to work with each block separately, how to do this? So I made it selenium to find all elements with the same block class, that is, to work with each block separately (using "for") and what is next? How to take a photo or names specifically from one exact block? Of course, I can parse names, photos and something else separately from each other, but there is one problem, one of the blocks (friends) may have the university or mutual friends or none of these(empty), and if I will parse all separate, then the descriptions(university,mutual friends) will just stand up consistently as 1,2,3 ..., not including empty descriptions
If there are those who know, please help or share a link where I can read about it
Nov 24, 2020 in Selenium by Beks
• 120 points
1,437 views

2 answers to this question.

0 votes

Hi, @Beks,

Regarding your query, I would like to suggest you visit the given link as its matches the query you have mentioned 

https://www.edureka.co/community/49744/print-text-from-list-elements-with-same-class-name-selenium

https://www.edureka.co/community/55212/how-to-loop-through-a-menu-list-on-a-webpage-using-selenium

answered Nov 24, 2020 by Gitika
• 65,910 points
To be honest links did not help me, because in the links written only how to get only text by the loop! I need to get classes inside of the chosen one. I will show an example as code:

Let's say we have 3 div with same classes, inside of the every class have img and text also with similar classes, and in the div can exist one more text(it also can do not exist):

<div class="div_example">

    <img class="img_example" src="source1">

    <a class="name_example" href="#">Name Surname1</a>

</div>

<div class="div_example">

    <img class="img_example" src="source2">

    <i class="text_example">may not exist text</i>

    <a class="name_example" href="#">Name Surname2</a>

</div>

<div class="div_example">

    <img class="img_example" src="source3">

    <a class="name_example" href="#">Name Surname3</a>

</div>

So here let's say that I have started for loop to class "div_example", and it will loop 3 time and every time, I need to get class inside of the chosen one! That is, if loop on 1st round, than I need an access to the "img_example" class exactly on first div class. And how can I do it? How can I get class inside of chosen class?
0 votes

Hello @Beks,

You can simply use the jQuery each() method to loop through elements with the same class and perform some action based on the specific condition.

Here is the jQuery code in the following example will loop through each DIV elements:https://www.tutorialrepublic.com/faq/how-to-loop-through-elements-with-the-same-class-in-jquery.php

Hope now you got the idea how to iterate through same class name and use there property!!

answered Nov 25, 2020 by Niroj
• 82,880 points

Related Questions In Selenium

+1 vote
1 answer

How to handle notifications in Python with Selenium (Chrome WebDriver)

Below will help you: You can disable the ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
13,697 views
0 votes
2 answers

How to open a browser window in full screen using Selenium WebDriver with C#

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
15,529 views
0 votes
1 answer

How to replace remote resources with local resource in a page with Selenium?

You could change URL for that script ...READ MORE

answered Aug 8, 2018 in Selenium by Samarpit
• 5,910 points
3,820 views
0 votes
1 answer
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
12,620 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
8,572 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
6,629 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,519 views
0 votes
3 answers

How to print text from a list of all web elements with same class name in Selenium?

Try using List <WebElement> to access all similar elements ...READ MORE

answered Dec 16, 2020 in Selenium by Roshni
• 10,520 points
81,593 views
0 votes
6 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 13, 2019 in Selenium by anonymous
94,612 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