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,280 points
8,191 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,520 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,890 points
8,218 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 3, 2020 in Selenium by Sri
• 3,100 points
467 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
6,905 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,520 points
5,630 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,100 points
6,203 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,890 points
3,855 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,040 points
3,131 views
0 votes
1 answer