2011-08-03 24 views
1

使用Selenium 2中的高級用戶交互API(http://code.google.com/p/selenium/wiki/AdvancedUserInteractions)打開自定義上下文菜單時出現問題。Selenium中的上下文點擊2.2

下面是C#代碼:

var driver = new FirefoxDriver(); 
driver.Navigate().GoToUrl("http://www.flickr.com/photos/davidcampbellphotography/4581594452/"); 
IWebElement photoDiv = driver.FindElement(By.Id("photo")); 

Actions actions = new Actions(driver); 
var context = actions.ContextClick(photoDiv).Build(); 
context.Perform(); 

不過這段代碼沒有打開上下文菜單,但只需點擊圖像上。

還有很多其他交互工作正常,就像在this blogpost

我在Windows XP Selenium版本2.2上使用Firefox 5。

如有任何建議,請提前致謝。

UPDATE: 但是,here的代碼也是這樣(左鍵單擊而不是上下文單擊)。

ILocatable loc = (ILocatable)photoDiv; 
IMouse mouse = ((IHasInputDevices)driver).Mouse; 
mouse.ContextClick(loc.Coordinates); 
mouse.MouseMove(loc.Coordinates, 15, 15); 

看起來像一個錯誤。

回答

1

這似乎是that bug。 它在用戶組here中聲明,但該錯誤是關於雙擊。

2

您是否嘗試過使用機器人點擊,雖然他們沒有這樣做的最有效的方式,但只要在瀏覽器窗口頂部的窗口,它會點擊座標設置

Robot robot = new Robot(); 
    robot.mouseMove(650, 590); 
    robot.mousePress(InputEvent.BUTTON1_MASK); 
    robot.mouseRelease(InputEvent.BUTTON1_MASK); 

也許這會幫到你:-)

+0

謝謝!我將安裝Selenium並檢查它,並重新測試代碼以查看錯誤是否仍然存在。將在幾天內回報:) –