user621577
user621577

Reputation: 11

webdriver not clicking on button

I have a scenario where if if mouse hover a box it shows the button on which I want to click. The html is something like this:

<div class="Box on which hovering i get the button">
  <div class="special button comes only on hovering">

I am using this code to click on the webdriver but without any success:

(IrenderedWebElement)driver.hover(locatorOfBox)
(IrenderedWebElement)driver.click(special button locator)
if(button.isDisplayed)
driver.click

I have tried putting wait also in between hover and click but of no use. I am stuck so looking for answers.

Upvotes: 1

Views: 1209

Answers (3)

bugCracker
bugCracker

Reputation: 3796

Use Xpath (to locate exact button- it helps when id is autogenerated) to click on button

driver.findElement(By.xpath("//*[@class='Box on which hovering i get the button']/div")).click();

Hope below link will help to manually generate xpath

http://www.guru99.com/accessing-links-tables-selenium-webdriver.html
see under "Reading a Table-->XPath Syntax"

Upvotes: 0

Jonathan Moffatt
Jonathan Moffatt

Reputation: 13457

Use the Actions class. Here's an example where the "Rounds" sub menu item is only visible after hovering on the "Default management" top level menu item:

        IWebElement topLevelMenu = driver.FindElement(By.LinkText("DEFAULT MANAGEMENT"));
        var actions = new Actions(driver);
        actions.MoveToElement(topLevelMenu).Perform();
        driver.FindElement(By.LinkText("ROUNDS")).Click();

Upvotes: 1

mirza
mirza

Reputation: 5793

Try click first div class and after that click second.

Upvotes: 0

Related Questions