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 in Selenium by BlackJack
• 130 points
157 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
answered Jan 2 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,010 points
267 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,870 points
2,851 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 15, 2019 in Selenium by Raishul
791 views
0 votes
1 answer

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

@Rajni, following test case is somewhat similar ...READ MORE

answered Jun 20, 2019 in Selenium by Avantika
4,423 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,010 points
408 views
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,510 points
1,570 views
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,870 points
1,501 views
0 votes
1 answer
0 votes
1 answer