Quality Testing

Quality is delighting customers

How to handle mouse over and click action: Selenium

Hi All,
I have a menu control in my application, on mouse over it will display
the menu option. I want to handle this menu control. I can handle the
mouse over but unable to click on displayed menu options using
WebDriver. Can any one help me out.

Views: 1113

Reply to This

Replies to This Discussion

hiiiiii sreeee

u can use this code its defnetly work......

//mouse over main menu.
            Actions builder = new Actions(driver);
            WebElement tagElement = driver.findElement(By.xpath("write ur element xpath here(means main menu)"));
            builder.moveToElement(tagElement).build().perform();
            
            
            driver.findElement(By.linkText("type here ur sub menu name")).click();
            System.out.println("CBW home page is opened successfully");
            Thread.sleep(50);

Thanks you...

I have used directly the

command: open 

Target: That menu link (In the /(link name founded by using inspect element)) 

Value: blank

And it directly works and open that menu....

This can be done in 2 ways:

1. Through JavaScript executor:

((JavascriptExecutor) driver).executeScript("write the javascript method here which will call the mouseover of main menu element");

2. Through Actions class

String yourxpath = "Give the menu bar's element xpath here";

WebElement menu = driver.findElement(By.xpath(yourxpath));


Actions action = new Actions(driver);
action.moveToElement(menu).perform();

 

Thanks,

Raman

Thanks for the reply, I am new to Selenium so am a bit confused as to how to fit your answer into what I have written so far, I will give you my code and maybe you can help?

BTW, I use way2automation, I recently bought the course but I did not see any video for mouse overs, maybe I missed it?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class WebUI_project {

    
    public static void main(String[] args) {
        
        WebDriver driver = new FirefoxDriver();
        driver.get("https://xxxxxxxxxx.org");
        
        driver.findElement(By.xpath("//*[@id='UserName']")).sendKeys("xxxxxx@xxxxx.org");
        driver.findElement(By.xpath("//*[@id='Password']")).sendKeys("xxxxxxx");
        driver.findElement(By.xpath("//*[@id='Accept']")).click();
        driver.findElement(By.xpath("//*[@id='btnSubmit']")).click();
        driver.findElement(By.xpath("//*[@id='ctl00_menuMaster']/ul/li[1]/a/span")).click();

The next 2 lines are where I get stuck. The previous line is the file menu that I mouse over to get the submenu, the following lines are the submenu that I want to click on to get to the screen I want. (both lines do the same thing, I tried both ways to see if it would help)    I hope this makes sense 

 //driver.findElement(By.cssSelector("rmText User Maintenance")).click();
        driver.findElement(By.xpath("//*[@id='ctl00_menuMaster']/ul/li[1]/div/ul/li[3]/a/span")).click();
        

    }

}

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service