Jagaur
Jagaur

Reputation: 51

How to mouse over and click on " Mobiles section"

enter image description here

To move to Electronics menu:

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//*[@id='container']/div/header/div[2]/div/ul/li[1]/a/span[text()='Electronics']"))).build().perform();

To move Mobile Menu:

//WebElement mobile = (new WebDriverWait(driver,2)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='container']/div/header/div[2]/div/ul/li[1]/ul/li/ul/li[1]/ul/li[1]/a/span[1][text]()='Mobiles')")));

To click on the Mobiles:

// action.moveToElement(driver.findElement(By.xpath("//*[@id='container']/div/header/div[2]/div/ul/li[1]/ul/li/ul/li[1]/ul/li[1]/a/span[1][text]()='Mobiles')"))).click();

WebElement mobile=driver.findElement(By.xpath("html/body/div[1]/div/header/div[2]/div/ul/li[1]/ul/li/ul/li[1]/ul/li[1]/a/span[1][text]()='Mobiles')"));
mobile.click();

Tried the above code but didn't work error message displayed:

Xpath does not exist

Upvotes: 0

Views: 1078

Answers (1)

santhosh kumar
santhosh kumar

Reputation: 2019

We can use this xpath for the mobile element:

//a[@title='Electronics']

complete code to do mouse hover:

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//a[@title='Electronics']"))).click().build().perform();
//Clicking on the mobile tab
driver.findElement(by.xpath("//a[@title='Mobiles']")).click();

Hope this helps you. Thanks.

Upvotes: 1

Related Questions