Python Selenium - Trying to find element by link containing certain words

0 votes

I'm running a code that navigates through folders, arrives at a destination and downloads the file by simply clicking on it. For example, to find a folder, I'm using the below code:

find_element_by_link_text("Pricing and Catalogs")

The problem is that the folder sometimes isn't written exactly like that. For example, it has double spaces. So, i'm wondering if its possible to find an element by text that contains certain words? Something like below code:

find_element_by_link_text(containing "Pricing" and "Catalogs")

This is the html code:

<td class="ms-tv-item ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView_2" style="white-space:nowrap;"><a class="ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView_0 ms-tv-item ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeView_1" href="javascript:_spNavigateHierarchy(this,'','TAKES YOU TO SOME PAGE',false,'FolderNode', '')" title="Pricing  and  Catalogues" id="ctl00_PlaceHolderLeftNavBar_ctl02_WebTreeViewt223" style="border-style:none;font-size:1em;">Pricing  and  Catalogues</a></td>
Mar 28, 2018 in Selenium by code_ninja
• 6,300 points
9,307 views

1 answer to this question.

0 votes

2 issues. One thing is, "Catalogues" & "Catalogs" is spelt differently in html code and selenium code. Second is, by probably trying with XPath which will work. Sample code:

find_element_by_xpath("//a[contains(text(), 'Pricing') and contains(text(), 'Catalogues')]")
answered Mar 28, 2018 by nsv999
• 5,500 points

Related Questions In Selenium

+1 vote
1 answer
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,548 views
0 votes
2 answers

How to use link as a locator to find element in selenium?

driver.findElement(By.linkText("link")).click(); READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
1,686 views
0 votes
1 answer
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,772 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,568 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,084 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,178 views
0 votes
2 answers

Python & Selenium: How to find and click on YouTube's Like button

Hello Nitin, as the Like button on ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,140 points
5,387 views
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