Discovering interactive components in browser automation technology

I am currently working on automating tests using Java WebDriver with Eclipse and TestNG.

One of the challenges I am facing is locating an element named 'Tests 142' on a web page. The issue is that the number '142' in the element name keeps changing as it represents a count of records. I initially tried using partialLinkText technique to locate the element, but it failed because there is another element with the name 'Tests' on the page which interferes with the locator. Can anyone assist me in creating a dynamic element locator for 'Tests 142' that can accurately solve this problem?

HTML Code:

html>
<head>
<body>
<div id="errorMsgContainer" class="ui-widget-header"> </div>
 <script type="text/javascript">
 <style>
  <div id="help" class="help">
  <div class="wrapper">
  <div id="header">
  <div id="mainMenu">
  <br clear="all">
  <div class="siteWrapper">
  <div id="content">
  <div id="main" class="main">
  <h2>
  <ul id="" class="tabPane" style="padding-left:5px;">
  <div class="tabPage">
  <ul id="" class="tabPaneVertical" style="padding-left:5px;">
  <li id="items_" class="">
  <li id="items_" class="">
  <li id="items_" class="active">
  <div>
  <a href="/test2/1/p/a/projects/project/tests/project_id/1">
   Tests
  <span>142</span>
  </a>
  <div class="children">
  </div>
   </li>
  <li id="items_" class="">
  <li id="items_" class="">
  <li id="items_" class="">
  <li id="items_" class="">
  <li id="items_" class="">
  </ul>
  <div class="tabPageVertical">
  <script type="text/javascript">
   </div>
  </div>
  <div id="footer"></div>
  <div class="clear"></div>
  </div>
  <div class="footer">Powered by 2 © 2006-2013 v1.4.9.3</div>
  <script>
  </div>
  <div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>
  </body>
  </html>

Thank you for your assistance.

Answer №1

Initially, the HTML is quite muddled at the moment which may lead to inaccurate answers once it's rectified. Therefore, I will explain the process of identifying an element instead of giving a direct answer, as there seems to be some confusion.

To clear up any confusion regarding terminology, there isn't an element called "Tests 142" in the provided sample HTML. There exists an element that contains the text "Tests 142", but this is distinct from actually being named that. What we are truly seeking is the <a> tag that encloses this text (ignoring the surrounding <span> when extracting the text), or the <span> tag if solely interested in the numerical value.

For instance, the XPath expression //li[@id='items_']/div/a refers to an li element with id='items_' containing a div which surrounds a hyperlink. In this scenario (after tidying up the HTML), this corresponds to the section encompassing "Tests 142". Note that this selection does not rely on the specific text within the link itself; even if it read "Tests 804" or "jabberwocky", the XPath would still be applicable. If only concerned with the numeric value, one can focus on the <span> tag by utilizing the XPath //li[@id='items_']/div/a/span.

Here is a simplified version of the test HTML:

<html>
<body>
<div class="tabPage">
    <ul id="" class="tabPaneVertical" style="padding-left:5px;">
        <li id="items_" class="active">
            <div>
                <a href="/test2/1/p/a/projects/project/tests/project_id/1">
                    Tests <span>142</span>
                </a>
            </div>
        </li>
    </ul>
</div>
</body>
</html>

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

What is the process of linking MongoDB with a server?

My attempt to retrieve data from mongoDB while connecting to the server has led me to insert a value into mongoDB in the following manner: > use abc switched to db abc > db.ac.insert({name:"naveen"}) WriteResult({ "nInserted" : 1 }) > show coll ...

Issue with positioning in Excanvas VML

After struggling through the implementation of excanvas on ie8, I managed to sort out the dynamic element issue. The once hidden elements are now rendering properly throughout most of the app, but just when it seemed like all was going well, another proble ...

Identifying Mistakes to Address Promise Failures

I encountered unhandled promise rejection errors and attempted to catch them and log them after each .then statement. Unfortunately, I ran into an 'unexpected token' issue when running the code on my server due to the period before .try. Despit ...

Delete an element from an array after a specified timeout period

I'm currently working on a Vue component that is responsible for displaying notifications which should automatically disappear after a set time. My Alert component triggers an 'expired' event and then I handle this event in the parent compon ...

How to authenticate to Restheart for Mongodb using Java's HttpURLConnection

I have successfully set up and running a restful interface to mongodb using restheart. When sending a GET request through Chrome, the interface provides the correct response. However, when I try to access it using the following Java code with HttpURLConnec ...

Creating a function for loading dynamic content in XSLT can be achieved by following these steps

When I call the function collapseandexpand() for static elements only, it does not work. Now, how can I create the same function to handle dynamic content in xslt? Javascript Code: <script language="javascript" type="text/javascript> <xsl:text&g ...

Is it possible to dynamically modify the implementation class injected by Spring at runtime?

I have a class that has been injected by Spring in the applicationContext.xml file and I am looking to change the implementation without altering the applicationContext.xml. I came across AOP's "IntroductionInterceptor" but haven't found many us ...

"Error alert: The specified property 'Iscontains' cannot be read because it is undefined" appears in the script for this video

I am currently utilizing AJAX to interact with my backend code. I retrieve URLs from the database and then render them onto the DOM, displaying videos accordingly. However, I am encountering an issue where Uncaught TypeError: Cannot read property ' ...

The drop-down menu selection is non-functional on mobile and iPad devices when using Bootstrap

<div class="panel panel-default"> <select> <option value="B3">B3</option> <option value="B4">B4</option> <option value="B5">B5</option> & ...

Whenever I tap on an ImageView located in the toolbar, my application crashes - Fragments issues are to blame

My list of dependencies includes: implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' Displayed bel ...

Initiate a file download following the redirection of a user to a new page in NodeJS/Express

Overview I am currently developing a NodeJS project using Express. In the application, there are buttons visible to the public that trigger file downloads. These buttons are linked to protected routes which will redirect users to a login page if they are ...

What is the method to clearly pinpoint entities from the global namespace in Typescript?

Instead of relying on Javascript's prototype, I am considering utilizing the inheritance feature of Typescript. My goal is to incorporate some helpful methods in the class String within my designated namespace Util. This way, the String class can imp ...

What is causing ChromeDriver 2.31 to encounter startup issues within a Docker environment?

My Docker container is built on the ubuntu:xenial image. However, when attempting to run selenium with the Chrome webdriver, it seems to load indefinitely. >>> from selenium import webdriver >>> from selenium.webdriver.chrome.options imp ...

Information formatting logged

I am currently working on logging the findings from my test, but every log entry includes a timestamp. I am trying to structure the log in an array format so that it follows this pattern: "[Date/Time] User number 1 name Test (Pass or Fail) Button (Found ...

An issue occurred while attempting to retrieve information from the database table

'// Encounter: Unable to retrieve data from the table. // My Code const sql = require('mssql/msnodesqlv8'); const poolPromise = new sql.ConnectionPool({ driver: 'msnodesqlv8', server: "test.database.windows.net", ...

How can VueX be leveraged to add an item to an array and also delete an item from the same array?

https://stackblitz.com/edit/vue-script-setup-with-vuex-gfjaff?file=src/components/UserProfile.vue I'm currently working on a feature where I can input a name into a dispatch function and have it added to an array. Eventually, I plan to include a text ...

Issue with React functional component's useState implementation

Whenever I update the state within a function, it doesn't seem to work correctly. I am setting my state to the opposite value, but it's not changing on the second console log. However, the third console log shows true. Why is it not returning tr ...

Executing a statement concurrently with a wait.until command in Selenium

Is there a way to run a command while waiting for a specific element to appear? I am currently anticipating the appearance of an element, but it will only show up once the page is refreshed. Here is the code snippet that I am using: wait = new WebDriverWa ...

Navigating to a Link with the href Attribute in Python Using Selenium

Here is the format of the href: href="../s-reminderNotice.asp?fname=b%2D3c%2DpLessonBooking%2Easp%3Flimit%3Dpl" https://i.sstatic.net/S7k0f.png All I want to do is automatically click this text link on a website. The code I have written for it is: drive ...

Dialogue Inventory System

I am in the process of developing a conversation system that includes a page where users can view all of their conversations and select which one they want to reply to. The layout is structured as follows: You can view an image of the layout here. The co ...