Can you show me the procedure for retrieving a particular element with selenium? (Page Source provided)

Disclaimer: I must admit that my knowledge of HTML and CSS is minimal, so please bear with me!

Hello everyone, I am attempting to utilize selenium[Java] to browse a website and retrieve a file. While I managed to successfully get past the login page, I find myself struggling to navigate through the site at this point.

https://i.sstatic.net/cdEig.png

My current objective is to "click" on the last item in the list, however, I am unable to identify this particular item or its parent root element. Any assistance would be greatly appreciated!

As a side note, I am using HtmlUnitDriver - could this potentially be causing any conflicts?

Answer №1

If you have the total count of "li" elements, you can experiment with the following method...

 jsString ="$('.x-tree-root-ct li:nth-child(4)').find("div")[0].click()"
 //or
 //jsString ="$('#ext-gen-top123 li:nth-child(4)').find("div")[0].click()"

  //execute the above JavaScript code using 
  WebDriver driver = new FirefoxDriver();
  JavascriptExecutor js = null;
    if(driver instanceof JavascriptExecutor) {
        js = (JavascriptExecutor) driver;
        js.executeScript(jsString)
}

Hopefully, this explanation is helpful to you.

Answer №2

Have you considered utilizing xpath for this task?

WebElement element = driver.findElement(By.xpath("//li[@id='ext-gen-top281']/div[contains(@id, 'Management/Search')));

I am unsure as to why the element cannot be found simply by its ID.

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

Orientation remains constant (Actionbar and ICS)

I'm encountering an issue with ICS and the Actionbar. Initially, when I changed the orientation, everything was working fine. However, now when I change the orientation, I'm faced with the following error: Caused by: android.support.v4.app.Fragm ...

After processing PHP code, display the page to the user immediately

When a user is on index.php: <form align="center" action="send.php" method="post"> address:<input type="text" name="address"/><br> <input id="submit" type="submit" name="submit" value=""> </form> I want to create a f ...

Scrolling to the complete height of a div using scrollTop

Experience an automated scroll to the bottom of the div, followed by a smooth upward motion over 5 seconds, all while looping seamlessly. A small issue arises where the code only recognizes the standard height set for the div, not its actual scrollable he ...

How to format datetime in Android using Django conventions

Currently, I am establishing a connection between my Django website and an Android app using JSON and the REST framework. The JSON data that is being transferred includes datetime information in the following format: { date: "2018-06-05T12:42:48.54514 ...

"Consolidate all cucumber reports into a single Jenkins report for easy analysis

In my Jenkins setup, I have 4 separate builds that each produce a cucumber report. I am trying to figure out how to merge these individual reports into a single comprehensive one, but haven't been able to find a solution yet. If anyone has any ideas ...

Update the default monospaced font in Draft.js

Is it possible to change the default system monospace font in Draft Editor to Consolas using Draft.css or global css classes? ...

Is it possible to mix units within the 'path' element in SVG?

Utilizing SVG's rectangle element, you can specify dimensions as a percentage of its owner's dimensions and set a radius in pixels. By using the code below: <div style="position: relative;"> <object class="AIRound" t ...

Tips for accurately obtaining row counts from a dynamic table when the `<tr>` numbers are constantly fluctuating

One issue that I encountered as a tester involved verifying the total number of rows on a dynamic table. Despite having 50 rows in the table, the HTML only displayed a maximum of 22 <tr>. This discrepancy caused my automation code to return an incorr ...

Adding borders to div elements for mobile display

Almost done with my website homepage, but I'm noticing some pesky borders/outlines on mobile devices. This issue doesn't seem to pop up on computers, so you'll need an iPhone, tablet, or smartphone to see what I'm talking about. Check o ...

Is there a restriction on the maximum size of a CSS file?

Currently, I am working on building a site using ASP.NET MVC. The CSS file that I have been working on has now grown to 88KB in size and contains over 5,000 lines of code. Recently, I have noticed that some styles that I added towards the end of the file a ...

Error in HTML5 video: Unable to access property '0' as it is undefined

I am trying to create a simple block displaying an HTML5 video tag. I want the ability to play different videos along with their titles from a JSON file by using previous and next buttons. Clicking the next button should play the next video, and the same g ...

Tips for aligning inputs vertically and stretching them horizontally with bootstrap flex only

For a practice exercise, I want to achieve vertical left alignment and horizontal stretching of input fields using only Bootstrap Flex (or CSS3 flexbox), without relying on Bootstrap Grid or CSS3 grid layout. Here is the code snippet (also available on co ...

Stylish Card Design

Below is the CSS code: *{margin:0; padding:0; box-sizing:border-box; } img{ display:block; max-width:100%; height:auto; } html{ scroll-behavior:smooth; } body{ min-height:100vh; font-family:fantasy; font-size:1.12 ...

Tips for including a wildcard in a MySQL query while using the '=' operator

I am working with pre parameters that determine the input for my query. For one scenario, I need to search for all UUIDs, while in another situation, I only want to look for specific UUID numbers. Instead of splitting this into two separate calls as shown ...

Is the Selenium element being clicked at the incorrect position?

We are currently waiting for a button to become clickable using its xpath in Selenium. Once it's ready, we're trying to click on it by utilizing the ExpectedConditions.elementToBeClickable() method. However, upon attempting to click on the butto ...

What are the steps to troubleshoot a NullPointerException error in apache.jena.queryExecutionFactory while attempting to create

Currently, I am utilizing org.apache.jena with karaf. When attempting to query my model, I encountered a NullPointerException. After examining all the variables used in creating the query (queryString, inferedModel), none of them are null. Here is a snippe ...

Debugging Slideshows Using JavaScript

I am currently working on creating a slideshow and I'm facing some challenges with the JavaScript functionality. Everything seems to be running smoothly except for one issue - when I click right once, it transitions correctly, but if I then click left ...

Is it possible to align the link to the right side of the footer?

I am puzzled as to why the Back to top link does not float to the right of the "footer area" which has a width of 960px. Upon running my code, the back to top link ends up in the middle of the footer. Here is the snippet of my code - can anyone identify th ...

How can you set a condition for when no matches are found in a list filter?

I recently came across a fascinating example on W3 Schools that taught me how to implement a search filter. Below, I have customized it for everyone's reference. I am interested in modifying it to only display a list item with the message: No matche ...

Is the displayed Cyrillic string in the incorrect character set?

I am facing an issue with extracting a value from a decoded JSON response obtained from a Russian API. The value within the JSON = Object268 Initially, it appeared as: Объект 268 After including <meta charset="utf-8"> in my html ...