Unable to locate the input element using xpath

I am having trouble retrieving an input element using xpath as the return statement is false.

Oddly enough when attempting to retrieve the label, which is the only sibling of the input, it returns true. I also tried to target it using input[@type="checkbox"] but without success.

try {
    var select2 = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.xpath('//div[@class="arcHier arcVert arcTree"]/ol/li/ul/li[3]/div[@class="dragNode"]/label')))

    WDS.log.info('select2 found')

    var select3 = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.xpath('//div[@class="arcHier arcVert arcTree"]/ol/li/ul/li[3]/div[@class="dragNode"]/input')))

    WDS.log.info('select3 found')
}
catch (err) {
     WDS.log.error('item not found')
}

HTML structure:

<li id="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef_LI" style="line-height:19px;border-color:#a0a0a0;color:#000000;" class="LI_1_2">
    <label class="arcSelectable" style="height:19px;">
        <input type="checkbox" id="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef_X" class="arcHpCbox" checked="checked">
        <span class="arcMenuCheckbox"></span>
    </label>
    <div class="dragNode">
        <input type="checkbox" id="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef" style="margin-top:3px;">
        <label draggable="false" for="4_2_1_292719_8381e915e3af18b6f1f672da1ee582ef" style="height:19px;">
            <span class="SPAN_1_2" style=""></span>
0001 Training_Test_Company
        </label>
    </div>
</li>

The logs file:

  1. 2019-07-10 10:55:33,187 INFO c.g.j.p.w.s.WebDriverSampler: select2 found
  2. 2019-07-10 10:55:43,310 ERROR c.g.j.p.w.s.WebDriverSampler: item not found

Answer №1

To hide the input element, you can use a hidden checkbox. Instead of using visibilityOfElementLocated, you can experiment with presenceOfElementLocated as shown below.

try {
    var select2 = wait.until(pkg.ExpectedConditions.visibilityOfElementLocated(pkg.By.xpath('//div[@class="arcHier arcVert arcTree"]/ol/li/ul/li[3]/div[@class="dragNode"]/label')))

    WDS.log.info('select2 found')

    var select3 = wait.until(pkg.ExpectedConditions.presenceOfElementLocated(pkg.By.xpath('//div[@class="arcHier arcVert arcTree"]/ol/li/ul/li[3]/div[@class="dragNode"]/input')))

    WDS.log.info('select3 found')
}
catch (err) {
     WDS.log.error('item not found')
}

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

c# server-side method is failing to execute when called from an AJAX request in ASP.NET

I am attempting to utilize ajax to call a C# method in the following manner. <a href="#divrecentQ" id="linkdivrecentQ" onclick="lnkClick();" aria-controls="divrecentQ" role="tab" data-toggle="tab&qu ...

Obtain Outcome from a Nested Function in Node.js

I'm grappling with the concept of manipulating the stack in JS and hoping this exercise will provide some clarity. Currently, I'm attempting to create a function that makes a SOAP XML call, parses the data, and returns it when called. While I c ...

Unleashing the power of async/await in React: A comprehensive guide

Looking to simplify my code, I am interested in implementing async and await for the following code snippet. However, I am unsure of how to proceed. Any examples would be greatly appreciated. deletePost = (post) => { var post_id = post; try { ...

When a React CSS class is deployed to a production server, it may be automatically

I've encountered a strange CSS issue while working on my React project. One specific section of the JSX <div> has a class with style properties defined in the main .css file. During local development, everything appears as expected. However, aft ...

Tips for stopping a Node.js for loop if it runs for more than 20 seconds

Imagine a situation where I have a for loop performing some actions, and I want to terminate the loop if it takes longer than 20 seconds to complete. async function mainFunc(){ for (let step = 0; step < 5; step++) { // Executes a complex op ...

Tips for changing the value of a Django query set?

I have a query: def get_comment_tree(request): news_id = request.GET.get("news_id") ret = list(Comment.objects.filter(news_id=news_id).values("nid", "content", "parent_comment_id", "user", "cre ...

Delaying loops with JQuery Ajax

I am attempting to implement a delay in my AJAX data processing so that the loop runs a bit slower. Here's the code I'm working with: $(document).ready(function (){ $('#button').click(function(){ $('#hide').show ...

Utilize the request object from Express within a Mongoose Plugin

I have incorporated an API in ExpressJS along with a middleware that runs before each endpoint controller: app.use(segregationMiddleware); app.get('/some-endpoint', controller1); app.get('/some-endpoint-2', controller2); The segregat ...

Exploring Material UI: Understanding the contrast in functionalities between incorporating the Icon component and the Material Icons node

I am looking to incorporate Material Icons into my application. I have come across two methods provided by Material UI for adding the same icon to my site: Using the <Icon /> component, which is part of the @material-ui/core package: <!-- Add t ...

Webdriver will automatically open a file as soon as the download is complete

I am currently creating tests and utilizing the Firefox webdriver along with a FirefoxProfile to download a file from an external source. However, I need to be able to read this file immediately after it has finished downloading in order to extract specifi ...

Using Ajax to preview images results in displaying a broken image icon

I am currently working on implementing an image preview function using Ajax. As I was experimenting, a couple of questions came to my mind: Once the Ajax has been executed, is the actual image uploaded to the server or just an array containing strings l ...

Each time the page is reloaded, the animation's frames per second (fps

In my project, I have two main pages: 'index' and 'about'. The 'about' page includes a cool animation that you can check out here. The issue I'm facing is that when I navigate from the 'index' page to the &apos ...

Enhancing jQuery Functionality with Parameter Overrides

While it may seem like a simple question, I am new to writing jQuery plugins and could use some clarity on scope rules in JavaScript. My goal is to create a jQuery plugin that interacts with the Stack Overflow API. I have started exploring the Flair API f ...

Exploring the world of JSON manipulation in JavaScript

I've been experimenting with JSON recently and came across something I don't quite understand. Here is an example of some code I used: var str = "{'name':'vvv'}"; var cjson = eval ("(" + str + ")"); alert( ...

Manipulating float values in jQuery is similar to formatting numbers in PHP with the number_format() function

I am looking for a way to output floating numbers in JavaScript that functions exactly like the number_format function in PHP. Sample Javascript Code Math.round(totalCredit).toFixed(2) Sample PHP Code echo number_format(22212 , 2); The code above re ...

Differences between JSX and creating instances of component classes

Could someone please clarify the distinction between the following two statements? let instance1 = new CustomComponent(); and let instance2 = <CustomComponent /> When checking in the Chrome debugger, I see the following: for instance1 CustomComp ...

Is it possible to pass a parameter to a PHP controller using JavaScript without relying on jQuery or AJAX?

Is it possible to achieve the task at hand? That's the main question here. My goal is to extract data from a popup window and then, upon closing it, send this extracted content to a PHP controller for further processing. I'm facing conflicts wi ...

Developing user registration and authentication using Backbone.js in conjunction with Django Rest Framework

In the process of developing my app, I am utilizing backbone.js for the frontend and django-rest-framework for the backend. My goal is to enable user registration, login, logout functionality, and be able to verify whether a user is logged in using backbon ...

What are the steps to enable a web app on a user's home screen?

Hey there! I'm looking to add a small popup with a button at the end of my website to prompt users to add it to their phone's home screen. I followed a tutorial that helped me achieve this on Android, but unfortunately, it only works with https a ...

Utilizing the Aladin Lite application within a React application, despite not being specifically designed for React

I am interested in incorporating the Aladin Lite app into my React application. Typically, embedding the app in a div is straightforward when developing a website without React: <!-- include Aladin Lite CSS file in the head section of your page --> ...