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.