Selenium2 WebDriver Ruby => how click on a hidden link

后端 未结 3 1609
北恋
北恋 2021-01-06 01:59

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.

3条回答
  •  难免孤独
    2021-01-06 02:14

    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.

提交回复
热议问题