Having trouble finding the element with the xpath/css locator in Selenium

I am currently developing a tree view folder structure. Here is the code snippet I am working with:

Code:

package Selenium_Practice;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Folder_Navigation {

    public static void main(String[] args) {

        System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\Selenium_Practice\\EXEs\\geckodriver-v0.10.0-win64\\geckodriver.exe");

        WebDriver driver = new FirefoxDriver();

        driver.get("http://alfrescocontint:8080/alfresco");

        driver.manage().window().maximize();

        WebDriverWait wait = new WebDriverWait(driver,30);

        wait.until(ExpectedConditions.elementToBeClickable(By.id("loginForm:submit")));

        driver.findElement(By.id("loginForm:user-name")).clear();
        driver.findElement(By.id("loginForm:user-name")).sendKeys("admin");

        driver.findElement(By.id("loginForm:user-password")).clear();
        driver.findElement(By.id("loginForm:user-password")).sendKeys("admin");

        driver.findElement(By.id("loginForm:submit")).click();

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        driver.findElement(By.xpath("//div[@id='navigator']/div[2]/a")).click();

        driver.findElement(By.cssSelector("img[id='ygtvt26']")).click();

        driver.findElement(By.cssSelector("img[id='ygtvt30']")).click();

        driver.findElement(By.cssSelector("img[id='ygtvt32']")).click();

        driver.findElement(By.cssSelector("img[id='ygtvt33']")).click();

        driver.findElement(By.xpath("//*[@id='ygtvcontentel38']/span")).click();
    }

}

Code snippet:

<div id="ygtv32" class="ygtvitem">
<div class="treeNode" style="margin-left: 14px;">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<img id="ygtvt32" class="ygtvtp" src="/alfresco/images/icons/arrow_open.gif" onclick="javascript:YAHOO.widget.TreeView.getNode('treeContainer',32).toggle()"/>
</td>
<td onclick="treeNodeSelected("workspace://SpacesStore/20fdf23c-50ed-4e8f-9af8-262c35c80dde");">
<td id="ygtvcontentel32" onclick="treeNodeSelected("workspace://SpacesStore/20fdf23c-50ed-4e8f-9af8-262c35c80dde");">
</tr>
</tbody>
</table>
</div>
<div id="ygtvc32" class="ygtvchildren" style="">
</div>

Error:

1470997671795 Marionette: Element is missing an accesible name -> id: loginForm:user-name, tagName: INPUT, className: 
1470997671848 Marionette: Element does not have a correct accessibility role and may not be manipulated via the accessibility API -> id: loginForm:user-    password, tagName: INPUT, className: 
JavaScript warning: https://normandy.cdn.mozilla.net/static/bundles/selfrepair-72948156b77d6ce320e0.1e946d807ad4.js, line 11001: mutating the [[Prototype]] of  an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
1470997678274 Marionette: Element does not have a correct accessibility role and may not be manipulated via the accessibility API -> id: ygtvt26, tagName: IMG,     className: ygtvtn
1470997678426 Marionette: Element does not have a correct accessibility role and may not be manipulated via the accessibility API -> id: ygtvt30, tagName: IMG,     className: ygtvtp
Exception in thread "main" ...

It is evident that the image id is constantly changing, causing the script to fail. These folders are dynamically created due to data generation in another application.

Any suggestions for effectively identifying elements during each iteration would be greatly appreciated.

Answer №2

It seems like your goal is to select all the "tree nodes" on the webpage. One way to achieve this is by locating all the nodes based on their great-grandparent's div element. Here is a piece of code that demonstrates this:

    List<WebElement> treeNodes = driver.findElements(new By.ByCssSelector("div.ygtvitem"));
    for (WebElement node : treeNodes) {
        node.click();
    }

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 exactly is the significance of the "contains(., 'some text')" function when utilizing XPath in Selenium?

As someone who is just beginning with selenium coding, I've noticed a few xpaths that include (.,'followed by something'). Can you clarify what the . refers to in this context? ...

The carousel indicators in Bootstrap 4 are not responding to the CSS styles

I'm having trouble customizing the bootstrap 4 carousel indicators to look like the example image below. https://i.sstatic.net/Xdmim.png .carousel-indicators { width: auto; padding: 8px 18px; background-color: rgba(96,107,114,.8); ...

<Select> Placeholder customization

For my react project, I am utilizing material-Ui and I am looking to have a placeholder that stands out by having grey text instead of black when compared to the selected item. <Select name="answer" value={values.answer} onChange={handleChange} onBlur= ...

Tips for redesigning your Bootstrap slider

Looking to update the carousel design for the previous and next buttons with a new look. I've attempted the following code: .carousel-control-prev { content: 'prev'; font-size: 55px; color: red; } <a class="carousel-control-next" ...

Selecting a radio button value based on the specified sheet page using Java and Selenium Webdriver

Is there a way to use Java and Selenium Webdriver to read a value from a worksheet and then select the same value in a radio button on a webpage? Workbook workbook = Workbook.getWorkbook(new File("C:/plan.xls")); Sheet sheet = workbook.getSheet ...

Unveiling the concealed Selenium input with Python clicks

I am endeavoring to automate the login process using Selenium in Firefox with Python. Here is an example of what a login button looks like in HTML: <td> <input name="cmd" value="lg" type="hidden"> <input src="ok.png" style="border-sty ...

Is there a way to style alternate iframes using CSS?

I need to select every second iframe in the image provided. Is it possible to achieve this using nth-child? I have tried with the following code (unsuccessfully): #main iframe:nth-child(2n+2) ...

What is the best way to implement backup style attributes for a React JS component?

Is there a method to implement fallback style properties for a component? For example: var inlineStyle = { display: '-webkit-box', display: '-webkit-flex', display: '-moz-box', display: '-moz-flex', ...

Trouble arises when implementing personalized buttons on the Slick JS slider

Are you struggling to customize buttons for your Slick Slider JS? I am facing a similar issue with applying my own button styles to the slider. I am interested in using arrow icons instead of the default buttons. Here is the HTML code snippet: <secti ...

When working with Selenium and Java, I am facing an issue where the "Actions" function keeps releasing the element from my cursor, even when

Having trouble using the action class to drag and drop an element to a specific zone. The element always seems to be dropped where my real mouse cursor is, as shown in this example: element is dropped even out of the browser Check out my code snippet bel ...

Can Selenium provide me with a numerical value?

I recently started using Selenium and I've encountered a problem. The solution is probably simple, but I haven't been able to find it anywhere. When I attempt to locate an element with the code below: options = Options() options.binary_location= ...

Experiencing a "timeout: Renderer message not received within 120.000 seconds" error while using Chrome version 105

Upon clicking on an element, I am encountering an error even though the element is clicked correctly. The error message received is as follows: org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 120.000 (Session info: ...

What are the steps to implementing PNG masking using PixiJS?

I am currently working on incorporating a png sprite as a mask for another layer. I found a demo on the pixi.js official website and created this fiddle: https://jsfiddle.net/raphadko/ukc1rwrc/ The code snippet below is what I am using for the masking fu ...

The code is malfunctioning on this site (yet functions perfectly on a different website)

So I have a question that may seem silly, but it's worth asking. I'm attempting to create a sticky div element that stays in place when you scroll past a certain point on the page. This is the script I have: <script type="text/javascript"> ...

Modify the color of the components in Select from Material-UI

After reviewing numerous questions and answers on this topic, I have yet to find a suitable solution for my issue. Seeking guidance from the community for assistance. Utilizing the Select component from @mui/material to showcase the number of records per ...

The method gettext() is not defined for the object type, prompting a compile error that requires casting

Currently learning Java and dipping my toes into selenium for testing. Took an online course to get started, but I've hit a roadblock with a compilation error in my code. It's been preventing me from making progress, so any help would be greatly ...

Place in the Middle of a Bootstrap Container

Struggling with aligning the elements of a Bootstrap well in the center? The badge is off to the side instead of below the arrows, and the vote buttons are not centered within the well. Check out the code snippet below: HTML: <div class="col-md-1 ...

Thumbnails on the grid are vertically aligned to the top

How can I vertically align grid items at the top without manually setting grid span properties for li elements? I need the layout to be flexible and work for any number of list elements. ul { position: absolute; left: 0; top: 0; width: 400px; ...

Encountered an error while trying to select an option from a dropdown menu using Selenium Python - TypeError: 'Select' object is not callable

Encountering a problem: Error Message: TypeError: 'Select' object is not callable when trying to choose an option from a dropdown menu in Selenium Python. Here are the steps I tried: Select = Select(driver.find_element(By.NAME, "delivery-s ...

How can you switch the display between two different class names using JavaScript?

I currently have a total of four filter buttons on my website, and I only want two of them to be visible at any given time. To achieve this, I labeled the first set of buttons as .switch1 and the second set as .switch2. Now, I've added a 'switch ...