Python Selenium How to locate elements in span class not unique ID

+1 vote

Hello there people,

Im starting my way in automation and until now all i see is huge challenge :)

Im trying to automate web UI in my workplace using selenium with Python with chrome browser and many of the elements are not unique and I just cant locate their element, not even when copying xpath or css.

few examples:

1. Im trying to verify if "Top Alerts" text exists in the page but when inspecting the element i get this:

```<span class="MuiTypography-root jss819 jss815 block-title MuiTypography-body1">Top Alerts</span>```

and i cant pull anything from the span class. even tried to pull it as css selector with dots between the sentences and in the beginning.

2. Another example is that i have in some app some links in rows but checking the element wont give me something that i can work with, and even when going up in hierarchy will give me some attribute that im not sure how to work with:

i will be more than happy to get help from this forum for a solution.

Thank you very much

Jan 1, 2020 in Selenium by BlackJack
• 130 points
10,375 views
Could you share your code snippets that you used to achieve these?

1 answer to this question.

0 votes

I use the following code to check if a text exists in the page:

if (check_exists_by_link_text(driver, "Top Alerts")):
    #do something


Hope this Helps!!

To learn more, join the online course to do Masters in Python.

Thanks!

answered Jan 2, 2020 by Karan

Thanks for the comment Karan.

I found a few solutions for the first issue:

1. topAlerts = driver.find_element_by_xpath("//*[contains(text(), 'Top Alerts')]") 

    print(topAlerts.is_displayed())
2.  topAlerts = driver.find_element_by_xpath("//*[contains(text(), 'Top Alerts')]").is_displayed()

if topAlerts == True:
    assert True
else:
    assert False

for the second issue, i didn't find solution yet


Related Questions In Selenium

0 votes
1 answer

How to locate web elements in Selenium-Python?

@Urvashi in Python, Selenium Webdriver API supports ...READ MORE

answered May 27, 2019 in Selenium by Anvi
• 14,150 points
14,777 views
0 votes
1 answer

How to find Elements by their Attribute in Python Selenium WebDriver

To find all the <td> tags which have attribute data-sortable-id you ...READ MORE

answered Jul 19, 2018 in Selenium by Samarpit
• 5,910 points
10,579 views
0 votes
0 answers

How to hover element when action class is not working in my Selenium framework ?

When i am writing the code to ...READ MORE

Feb 16, 2019 in Selenium by Raishul
3,925 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,480 points
87,427 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8, 2019 in Selenium by Anvi
• 14,150 points
15,837 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,673 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,142 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,221 views
0 votes
1 answer
0 votes
1 answer
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