1

I am trying to automate the process of downloading a file through an online tool. I am using Selenium 3.0.1, and new to it. What am i trying to do?

  1. Login
  2. Move to specific element
  3. From there, Find the element which I need to double click

I am struggling to finding the element. I've done quite a bit of googling but still unable to find the element.

Here is the front end(I don't know how to copy past the html directly): enter image description here

I am trying to get to the div ext:tree-node-id="xnode-520" (second last line in the picture) I want to get there but I'm unable to, I'm not sure if the unselectable="on" attribute is effecting that.

Here is my code:

public class Main {

public static void main(String[] args) {

    String exePath = "C://Users//user1//Documents//chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    WebDriver driver = new ChromeDriver();
    Actions action = new Actions(driver);

    driver.get("website url");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.id("username")).sendKeys("u9");
    driver.findElement(By.name("password")).sendKeys("u9");
    driver.findElement(By.id("ext-gen24")).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    WebElement findElement = driver.findElement(By.id("ext-gen277"));

    WebElement findElement2 = driver.findElement(By.id("ext-gen278"));

    action.moveToElement(findElement);
    action.moveToElement(findElement2);

    String genXPath= "//div[@tree-node-id='xnode-520']";
    driver.findElement(By.xpath(genXPath)).click();
}
}

I left the website url generic for privacy purpose. I haven't really used the Actions class that much at all. I'm relatively new to this and I'm unaware of this dynamic front end.

EDIT: The exception that is being thrown is that the element is not clickable at point..Other element would receive the click

EDIT #2: Well this seems even more complicated the id numbers are changing everytime the page loads.

1

If the structure of the HTML does not change, a simple CSS selector can be useful.

By.cssSelector("div.xpanel ul.x-tree-root-ct li.tree-node div.x-tree-node-el")

This will select the first element of the tree. If you need to select other element - let's say - the third one:

 By.cssSelector("div.xpanel ul.x-tree-root-ct li.tree-node:nth-of-type(3) div.x-tree-node-el")

With the nth-of-type option and a bit of string concatenation, you can easily select dynamically any element of the tree.

  • It's unable to find the element "no such element" I think the css-selector needed a fix. The ul.x-tree-root-node should have been div.x-tree-root-node. Also I cant spot a div with class xpanel, I see xpanel-body – Nabz Nov 29 '16 at 15:36
  • You're right about the ul's class; already edited the answer. One could use the div.x-tree-root-node, but the ul makes clear that you are entering into a list. The 'div.x-tree-root-node' is the third div, from up to below. It has id = "ext-comp-1009". This part is to make sure you don't fall into a list (ul) inside the div.app-header node. – João Farias Dec 1 '16 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.