Span element not found using xpath

Recently updated the outer html and encountered a new error. It appears that the element was identified but failed to be clicked on.

My script fails at the element below. I have attempted various methods to reconstruct the xpath, but the robot continues to fail due to DOM invalidity.

Original element:

<div class="ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search">
<div class="ant-select-selector">
    <div class="ant-select-selection-overflow">
        <div class="ant-select-selection-overflow-item ant-select-selection-overflow-item-suffix" style="opacity: 1;">
            <div class="ant-select-selection-search" style="width: 3px;">
                <input autocomplete="off" type="search" class="ant-select-selection-search-input" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_2_list" aria-autocomplete="list" aria-controls="rc_select_2_list" aria-activedescendant="rc_select_2_list_0" value="" id="rc_select_2" style="opacity: 0;" aria-expanded="false" readonly="" unselectable="on">
                    <span class="ant-select-selection-search-mirror" aria-hidden="true">&nbsp;</span>
                </div>
            </div>
        </div>
        <span class="ant-select-selection-placeholder">Select Source(s)</span>
    </div>
</div>

Script:

*** Settings ***
Library    Browser
Library    OperatingSystem
Resource   ../Resources/BrowserParameters.robot
Resource   ../Resources/BrowserResources.robot
Resource   ../Resources/BrowserCustomKeywords.robot

#Select Browser: chromium or firefox
Test Setup      Test Setup    Browser=chromium
Test Teardown   Test Teardown

*** Test Cases ***
001
   Click     //span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')]

Error

    FAIL
Message:    TimeoutError: locator.click: Timeout 10000ms exceeded.
=========================== logs ===========================
waiting for selector "//span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')] >> nth=0"
  selector resolved to hidden <span class="ant-select-selection-placeholder">Select Source(s)</span>
attempting click action
  waiting for element to be visible, enabled and stable
    element is not stable - waiting...
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  checking that element receives pointer events at (1080.4,304.7)
  <div class="ant-select-selection-overflow">…</div> intercepts pointer events
retrying click action, attempt #1
  waiting for element to be visible, enabled and stable
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  checking that element receives pointer events at (1080.4,304.7)
    [ Message content over the limit has been removed. ]
  element is visible, enabled and stable
  scrolling into view if needed
  done scrolling
  checking that element receives pointer events at (1080.4,304.7)
  <div class="ant-select-selection-overflow">…</div> intercepts pointer events

By using this code, I am able to access the field and see the list being displayed. However, there are two fields in the form that use the same xpath. The robot accesses the first field, but I actually want it to go to the next field.

Click     //div[@class="ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search"]

Answer №1

You need to update your Xpath query from

//span[@class=""ant-select-selection-placeholder">Select Source(s)"]

to

//span[@class="ant-select-selection-placeholder"]

Alternatively,

//span[@class="ant-select-selection-placeholder" and (text()="Select Source(s)")]

Answer №2

This error message...

Error: The locator.click function encountered a DOMException error, specifically 'Failed to execute 'evaluate' on 'Document': The string './/span[@class=""ant-select-selection-placeholder">Select Source(s)"]' is not a valid XPath expression.

...indicates that the XPath you used is not a valid expression.

You need to make two small adjustments:

  • The value of the class attribute should be enclosed in single quotes, like this: "value"
  • Select Source(s) is the inner text, so you should refer to it as text.

Solution

You can use either of the following Locator Strategies:

  • xpath 1:

    //span[@class='ant-select-selection-placeholder' and starts-with(., 'Select Source')]
    
  • xpath 2:

    //span[@class='ant-select-selection-placeholder' and contains(., 'Select Source')]
    

Answer №3

Kindly utilize the xpath provided below

//span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')]

or

//span[contains(@class,'ant-select-selection-placeholder') and starts-with(text(),'Select Source')]

Ensure to inspect the dev tools (Google Chrome) to confirm if there is a distinct entry in the HTML DOM.

Instructions to verify:

Press F12 in Chrome -> navigate to element section -> perform a CTRL + F -> then paste the xpath and observe if your targeted element is highlighted with 1/1 matching node.

If there is 1/1 matching node, please ensure that :

  1. This div is not within an iframe.
  2. This div is not within a shadow-root.
  3. You are not within a new tab/window opened by selenium.

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

The console is not displaying the data from the useForm

I am working on a project to create a Gmail clone. I have implemented the useForm library for data validation. However, when I input data into the form and try to print it to the console, nothing is being displayed. const onSubmit = (data) => { ...

"Optimize Magellan Sidebar for Mobile Devices by Relocating it to the Bottom of the Page

After spending a week working with Foundation 5 framework, I'm curious if there is a straightforward way to make my magellan sidebar shift to the bottom of the page when viewed on mobile or tablets. <div data-magellan-expedition="fixed"> <di ...

Embedding a table row within an anchor element in Angular 4

Currently, I am facing an issue with a table that contains [routerLink] on each <tr>. This setup is preventing the "open link in a new tab" option from appearing when I right-click because there is no <a> tag. I attempted to enclose the table r ...

No form data in selenium webdriver after submission

When navigating through a page, I encounter an issue where data filled into one form does not carry over to the next form. Strangely enough, when performing the same actions manually instead of using webdriver, everything functions correctly and all the da ...

Tips for avoiding overflow while utilizing animations

In my current project, I am facing an issue with a container div that has the CSS property overflow: auto which cannot be removed. Inside this container, there is another div that toggles between showing and hiding using an animation triggered by a button ...

Create a rectangular container with text using CSS

Looking to achieve a square box design using CSS with specific dimensions? Want to insert text inside the square and ensure it is horizontally centered within the square? Check out this code snippet: #myid { width: 100px; height: 100px; ...

Using Column CSS Property with Google Maps in Chrome: A Potential Bug?

I'm facing an interesting issue and I could use some help understanding or fixing it. It seems like there might be a bug or a solution to this problem. I am currently working on a layout using the CSS3 property columns. Everything looks fine in Firefo ...

Error in main thread: WebDriverException was thrown due to an unknown error: DevToolsActivePort file is missing

I am currently facing an issue with setting up Citrix framework as it is not functioning properly. The error message I receive is: unknown error: DevToolsActivePort file doesn't exist I have attempted the following troubleshooting steps: ChromeOpt ...

Eliminating Redundant CSS Code Using PHP Storm

After upgrading to PHP Storm version 8.03, I came across an article that discussed the ability to search for duplicate CSS code using this link: . Although I have tried to find a way to automatically resolve these duplicate codes within PHP Storm, I have ...

Position the table at the bottom of the page using CSS

I'm experiencing an issue where my HTML is not rendering correctly. I need to move the table with the ID "footer" to the bottom of the page. Here's the structure of the situation: <div id="container"> <table id="footer"></tabl ...

No alert is currently active in Selenium

Need assistance with an error when trying to close a window for printing. The code works on my computer but fails on another. Here is the code snippet causing the issue: driver.SwitchTo().Alert().Dismiss (); Error message: OpenQA.Selenium.NoAlertPresent ...

Maintain consistent alignment of the backgrounds for each term-description pair within a definition list resembling a table

I am trying to style a definition list in HTML to resemble a table using th and td elements in two separate columns, while also having alternating row backgrounds. I have implemented the following CSS for this purpose: dl { font-family: Verdana, Genev ...

What is the method to verify if an element is disabled in robot framework?

<a href="#" class="paginate_button previous disabled" aria-controls="DataTables_Table_82" data-dt-idx="0" tabindex="-1" id="DataTables_Table_82_previous">Previous</a> *** Testing Scen ...

attempting to eliminate on-screen buttons by hovering over the video

Is there a way to make my video play on loop like a GIF without the controls ever showing? I want it to have a seamless playback experience. Any ideas would be appreciated. P.s. Don't worry about any StackOverflow errors when running the snippet. Than ...

Unable to implement CSS styles on the provided HTML code

I'm currently working on integrating evoPDF into my asp.net application. When I click on a part of the HTML file, I send that portion using AJAX. So far, everything is working well up to this point. However, when I try to use the following methods fro ...

Arranging an image to appear directly underneath another image upon hovering the mouse over it

I want image two to appear below image one when the mouse hovers over image one. <ul> <li> <img id="img1" src="imageone.png"> <br> <img id="img2" src="imagetwo.png"> </li> </ul> Any assistance ...

Ensure that the content inside the centrally aligned div is also aligned at the

Looking for a way to center a box on a website I'm designing? Instead of aligning it based on existing centering, use the following HTML / CSS code to ensure that the white box is perfectly centered on the page. .loading { position: fixed; z-in ...

"Enhance your browsing experience with a java-powered Browser

Are there possible methods to develop a Chrome / Chromium extension using Java? I attempted to use selenium for this purpose, but it seems limited to browser automation and unable to capture user events. If not feasible with Chrome/Chromium, are there oth ...

Fixture in Py.test: Implement function fixture within scope fixture

I've encountered a small issue with pytest fixtures and I could really use some assistance. Below are some function fixtures without their implementation details for brevity. @pytest.fixture() def get_driver(): pass @pytest.fixture() def login( ...

Showing information from page's table using find_element_by_xpath (Selenium with Python)

I am currently exploring the implementation of the find_element_by_xpath() method to locate table elements on a webpage and present them in either a display or print format. Below is an excerpt from the page content: <tbody id="listContainer_databody" ...