2013-02-12 100 views
2

我已經嘗試了這兩個代碼,它得到執行,但行動沒有得到執行,任何人都可以告訴我爲什麼?拖放得到執行,但它沒有得到執行 - webdriver

//Type one approach 
Actions action = new Actions(Browser.Driver); 
IWebElement sourceElement = Browser.Driver.FindElement(By.XPath(Filexpath)); 
IWebElement targetElement = Browser.Driver.FindElement(By.XPath(NewXpath)); 

//Type two approach 
Actions Sourcebuilder = new Actions(Browser.Driver); 
Actions SourceAction = Sourcebuilder.ClickAndHold(sourceElement); 
Sourcebuilder.Build(); 
SourceAction.Perform(); 



/// move and drop 
Actions builder = new Actions(Browser.Driver); 
Actions action = builder.MoveToElement(targetElement); 
builder.Release(targetElement); 
builder.Build(); 
action.Perform(); 

在此先感謝

回答

3

試試這個代碼:

Actions ac = new Actions(driver); 
ac.dragAndDrop(source element, target element); 
ac.build().perform(); 

它會點擊並保持在源元素的位置,移動到目標元素的位置,然後釋放鼠標。

或者

Actions ac = new Actions(driver); 
ac.dragAndDropBy(source element, xOffset, yOffset); 
ac.build().perform(); 

它會點擊並按住在源元素的位置,由給定的偏移移動,然後鬆開鼠標。

或者

Actions ac = new Actions(driver); 
    ac.clickAndHold(onElement); 
    ac.moveToElement(toElement); or ac.moveToElement(toElement, xOffset, yOffset); 
    ac.build().perform(); 

它會做上述兩個代碼的動作。

我在Java上編寫此代碼。您可以轉換爲您指定的語言。

Actions.

+0

謝謝你最後一個解決了問題 – 2013-02-12 14:32:42