I use Selenium 2 WebDriver on Ruby.
How it is possible click on hidden link, with css (display: none)? the link is submenu and is visible when mouse over on menu.
WebDriver emulates user actions, and doesn't allow clicking elements that a user wouldn't be able to click.
So you should do what a user would do: mouse over the menu before clicking. In Ruby you could do e.g.:
menu = driver.find_element(:id => "menu")
submenu = driver.find_element(:id => "submenu")
driver.action.move_to(menu).click(submenu).perform
The ActionBuilder class (returned by Driver#action) is documented here.
before you search the link and click it
@driver.execute_script('jQuery(":hidden","#nav-main").show()')
jQuery should be loaded
In the past, if I have not had much luck with the ActionBuilder methods, I just use pure javascript:
def mouse_over_and_out(element)
@driver.execute_script("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}", element)
yield element
@driver.execute_script("if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseout', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseout');}", element)
end
def wait_for_visibility(element)
wait = Selenium::WebDriver::Wait.new(:timeout => 15)
wait.until do
element.visible?
end
element
end
mouse_over_and_out(@driver.find_element(:css => "ul#nav-main li")) do |menu|
submenu = menu.find_element(:css => "ul li a")
wait_for_visibility(submenu).click
end