The selector By.PARTIAL_LINK_TEXT in Selenium is failing to meet the expected condition

I am trying to store the friend list of a Facebook ID. When I click on the Friends tab on the profile, the friend list should be opened if it's not blocked; otherwise, something else should open.

To determine if the friend list is opened or blocked, I select the element that is present when the friend list is opened:

try:
    WebDriverWait(browser, 4).until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT,"friends_all")))
except:
    print "Friend list is blocked"
    browser.close()

The HTML code of the element in question is:

<a class="_3c_ _3s-" href="https://www.facebook.com/tripti.vishnoiji/friends_all" aria-controls="pagelet_timeline_app_collection_100001042287600:2356318349:2" role="tab" aria-selected="true" name="All friends" id="u_jsonp_2_0">
 <span class="_3sz">All friends</span>
 <span class="_3d0"></span>
 <div class="_3s_"></div>
</a>

The output currently displayed is: friend list is blocked

I am puzzled as to why the element is not being selected.

Answer №1

Give this code a shot:

    Utilize the following snippet:
    WebDriverWait(browser, 4).until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT,"All friends")))

Hopefully this information proves beneficial!

Answer №2

Hyperlink Text

This technique provides a straightforward way to identify a hyperlink on your website by utilizing the text within the link.

For example:

<a href="http://www.google.com">Launch Google</a>

In this case, the Hyperlink Text is Launch Google.

Partial Hyperlink Text:

Alternatively, Partial Hyperlink Text refers to a partial portion of the complete Hyperlink Text, such as Launch, Google & Launch Google

Therefore, in the given example, possible Partial Hyperlink Text could be All, Friends & All Friends

If the HTML includes friends_all in the href attribute, it does not represent the partial hyperlink text.

Hence, if you wish to click on the link, you can utilize the following method:

WebDriverWait(browser, 4).until(EC.presence_of_element_located((By.XPATH,'//span[text()='All friends'])))

Answer №3

When referencing the href attribute of an a element, be sure that the actual link text is "All friends" and does not contain "friends_all"

Consider using the following code:

WebDriverWait(browser, 4).until(EC.presence_of_element_located((By.XPATH,'//a[span[text()="All friends"]]')))

or

WebDriverWait(browser, 4).until(EC.presence_of_element_located((By.LINK_TEXT,'All friends')))

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using jQuery to toggle visibility on click within WordPress

Looking for a way to make three buttons change color on hover and display different content when clicked? You're not alone! Despite searching through tutorials and forums, the solution remains elusive. The buttons are structured like this: <div i ...

How can you style the modal image to center it? Which <div> should you target for styling?

I'm facing an issue with my modal image within a Bootstrap 4 carousel that uses JQuery. When I open the modal, it doesn't appear centered on the screen. Could you advise me on which parent div to style and how? Additionally, how can I ensure the ...

Trouble arises when attempting to append a class through ng-class upon clicking

In a specific scenario, I am trying to change the border color from black to red in a div by appending a class using ng-class when clicked. However, when clicking a button, the modal opens but the class is not being appended as expected. <div ng-class ...

In order to position content at the center of a <div> element

Just recently delving into the world of Bootstrap, I've hit a roadblock. Here's my current conundrum: <div class="container px-4 py-5" id="hanging-icons"> <h2 class="pb-2 border-bottom">Work Experie ...

What steps can I take to make sure a jQuery Mobile table does not become responsive?

My goal is to make a table responsive by using media queries to hide optional columns on smaller devices. I need to hide two columns based on different screen sizes: @media screen and (max-width: 33em) { th.optional-1, td.optional-1 { display: no ...

Is there a way to make a glossy `selectInput()` extend beyond a `bslib::navset_card_pill()`?

The dilemma: My issue is that the selectInput() in my code gets cut off by the lower border of the card: library(shiny) # Version 1.7.4 library(bslib) # Version 0.5.0 ui <- page_fluid( navset_card_pill(nav_panel( title = "No overflow :(&quo ...

Creating a distinct file name for every execution in Log4jORGenerating a unique file name

I have an issue in my project with log4j where I am unable to create a new file each time I run the script. My requirement is to generate a file name in the format Filename_<DDMMYYYY_HHMMSS> every time the script runs. Despite trying different codes ...

Using C# with Selenium to configure proxy settings

Hey there, I recently purchased some residential proxies that require user:pass authentication as well as the address:port. Unfortunately, I'm having trouble authenticating it in Selenium C#. Below is the code I'm using to set up the proxy setti ...

material-icons appear differently when letter-spacing is applied in iOS browsers

To display levels using star icons from angular material, I wanted the stars to be shown next to each other. I attempted to achieve this by applying letter-spacing: -0.25rem;, but unfortunately it did not render correctly on iOS platforms (resulting in s ...

Incorporating text into the border without increasing the spacing

I managed to create a unique CSS shape using clip paths as the border of a div. However, I am now facing an issue where I cannot add text to this border without it getting cut off due to the way the shape was created (possibly because of overflow: hidden). ...

The issue of the drop-down menu not appearing persists when using HTML and CSS

ul#menu li ,ul.sub-menu li { list-style-type: none; float:left; } ul#menu li a ,ul.sub-menu li a { display: inline-block; width: 150px; height: 40px; text-decoration: none; line-height: 40px; text-align: center; color:rgb(235, 139, 13) ...

Align the asp.net content generated towards the left side

I am looking to optimize the layout of my asp.net code by shifting the content on all pages to the left side of the screen for better efficiency. Despite my efforts, I have been unable to find a suitable CSS solution that works universally across all view ...

Change the selection box to a checkbox

I am struggling to retrieve the value of a selection box inside jQuery. Specifically, I need to access the selection box value within a function that triggers on a checkbox change event: This is what I have so far: $('input').on('change& ...

Passing data to an iframe through Ajax request

I have been devoting my time to a special project, and I can proudly say that I am almost done with it. However, the hurdle I am facing right now revolves around the concept of *sending parameter to iframe*. My primary objective is to craft a basic editor ...

Flex items refusing to wrap in Firefox

I am facing an issue with my layout setup in different browsers. When I have a list of divs inside a flex div, it displays correctly in Chrome: However, in Firefox, it only shows a horizontal scroll with one line. Is there a way to prevent the forced hor ...

What is the Best Way to Retain My Firefox Settings While Handling a JavaScript Alert?

I'm encountering an issue when trying to download a file by clicking on a link. I have set my Firefox preferences to save the file in a specific location. However, upon clicking on this particular link, a popup appears that I must accept before the do ...

How to Customize the Navbar Position in Bootstrap 3 when the Brand/Logo is Collapsed

I am currently in the process of creating my first website and experimenting with the Bootstrap 3 framework. The navbar I have selected is designed to adjust based on screen size, collapsing into a small button for use on tablets and mobile devices. Howe ...

Background color of a scrolling overflow-x panel-primary in Bootstrap

Seeking help with a CSS issue related to a Bootstrap panel. When the overflow-x property is activated, the blue background color of the panel-heading transitions to white instead of staying blue. Any suggestions on how to maintain the blue color while keep ...

How can I prevent encountering the "unicode escape" error when trying to decode certain bytes?

Attempting to create a spambot for Google Forms to generate random answers for a school assignment proved challenging. After struggling to write the code from scratch, I stumbled upon a pre-written script (link). However, despite spending hours installing ...

Importing documents from various directories

I am currently developing a webpage that is stored in a separate folder from the main root directory. My goal is to integrate the newsletter.css file, header.php file, and services.jpg image into the page. The specific page I'm working on is located a ...