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 27, 2018 in Selenium by code_ninja
• 6,220 points
3,846 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 27, 2018 by nsv999
• 5,090 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,130 points
1,757 views
0 votes
1 answer

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

Hello @Jino, its amazing to explore ways ...READ MORE

answered Dec 21, 2018 in Selenium by Nabarupa
91 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 in Selenium by Anvi
• 12,840 points
140 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,090 points
557 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,130 points
891 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 in Selenium by Abha
• 22,960 points
585 views
0 votes
1 answer