Spidy
Spidy

Reputation: 23

How to use mouse over on over indentation menus

This is the flow i wanna automate (MARKED IN BOLD) ==>> I'm very new to selenium

File

New --> Project --> Java

                C#

                Perl

                Python

Consider only mouseover alone available in the menu elements, other then the last option (JAVA) which have click functionality

Script I:

            // MouseHover       
    WebElement menu = wd.findElement(By.linkText("Setup School"));

    WebElement submenu = wd.findElement(By.xpath("//a[contains(text(),'Edit')])[3]"));

    WebElement sidemenu = wd.findElement(By.linkText("Register School"));


    // Action
    Actions action = new Actions(wd);

    // Hover action     

    action.moveToElement(menu).build().perform();
    Thread.sleep(2000);;

    action.moveToElement(submenu).build().perform();
    Thread.sleep(2000);;

    action.moveToElement(sidemenu).perform();
    action.click(sidemenu).build().perform();

Script II:

            action.moveToElement(menu).build().perform();;
    wd.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);

    action.moveToElement(submenu).build().perform();;
    wd.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
        action.moveToElement(wd.findElement(By.xpath("//a[contains(text(),'Register School')]"))).click().build().perform();

I have tried all the options even Xpath contains(text, href), css and linktext but nothing is working.

Initially it mouseovers the first element (File) but it stucked in future process..!

            WebElement submenu = wd.findElement(By.xpath("/html/body/table/tbody/tr[2]/td/div/ul/li[3]/a"));
            WebElement submenu = wd.findElement(By.xpath("//a[contains(text(),'Edit')])[3]"));

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: The given selector //a[contains(text(),'Edit')])[3] is either invalid or does not result in a WebElement. The following error occurred:

InvalidSelectorError: Unable to locate an element with the xpath expression //a[contains(text(),'Edit')])[3] because of the following error: [Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: ""] Command duration or timeout: 8 milliseconds

For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'

Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=29.0.1, platform=XP, browserConnectionEnabled=true, nativeEvents=true, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]

Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: The given selector //a[contains(text(),'Edit')])[3] is either invalid or does not result in a WebElement.

The following error occurred:

InvalidSelectorError: Unable to locate an element with the xpath expression //a[contains(text(),'Edit')])[3] because of the following error: [Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: ""]

This is what im getting when ever changing the xpath(), css(), linktext().

Please help me out for resolving this.!

Upvotes: 0

Views: 479

Answers (1)

Santoshsarma
Santoshsarma

Reputation: 5667

Try with below locator.

By.xpath("(//a[contains(text(),'Edit')])[3]")

Upvotes: 1

Related Questions