2010-01-31 100 views
11

即時通訊嘗試使用硒進行右鍵單擊,有關如何操作的任何想法?如何使用硒右鍵單擊?

+2

你做了什麼你自己嗎?或者你想讓人們爲你做所有的工作? – Cromulent 2010-01-31 12:11:02

+0

可能重複的[JavaScript通過代碼模擬右鍵單擊](http://stackoverflow.com/questions/433919/javascript-simulate-right-click-through-code) – 2011-09-26 19:50:31

回答

4

請參閱docroots's answer硒。

要大致模擬JavaScript中的右鍵單擊,請查看JavaScript simulate right click through code

+0

有一個鏈接到重複的按鈕...我'我只是說... – 2010-02-07 09:13:31

+0

@Marc Gravell:我想這是在我達到3000之前;) – 2010-02-07 17:24:39

+0

我會刪除這個答案,但我不能,因爲它是公認的答案。 – 2012-08-17 12:41:48

2

對於我的問題(右鍵點擊後打開彈出窗口的元素),使用硒的:mouse_down_right(),然後使用mouse_up_right() 也可以。謝謝。

11

根據OpenQA.Selenium.Interactions Namespace

// step 1 - select the element you want to right-click 
var elementToRightClick = this.Driver.FindElement(By.Id("elementtoclickonhasthisid")); 
// step 2 - create and step up an Actions object with your driver 
var action = new OpenQA.Selenium.Interactions.Actions(this.Driver); 
action.ContextClick(elementToRightClick); 
// step 3 - execute the action 
action.Perform(); 
0

我試過ActionSequence它工作。

找不到ContextClick函數,您應該使用click。

所以,它應該是如下:

driver.actions().click(element,2).perform(); 

的元素是你的網絡元素,2表示右鍵。

0

硒,爲右鍵的方法 - ContextClick:

 public void RightClick(IWebElement target) 
     { 
      var builder = new Actions(driver); 
      builder.ContextClick(target); 
      builder.Perform(); 
     }