我無法點擊WebElement
(按鈕),因爲它被圈子隱藏。 (覆蓋)WebElement點擊被Selenium中的另一個WebElement阻擋
如何點擊按鈕?
注-001圓元素CAN移動。我可以移動這個圓圈,但有時會出現在按鈕後面。
注-002:我不想使用JavaScript按鈕點擊功能。 (JavascriptExecutor
/.executeScript()
/.execute()
)
如何知道圓圈在按鈕後面的位置?
謝謝大家!
我無法點擊WebElement
(按鈕),因爲它被圈子隱藏。 (覆蓋)WebElement點擊被Selenium中的另一個WebElement阻擋
如何點擊按鈕?
注-001圓元素CAN移動。我可以移動這個圓圈,但有時會出現在按鈕後面。
注-002:我不想使用JavaScript按鈕點擊功能。 (JavascriptExecutor
/.executeScript()
/.execute()
)
如何知道圓圈在按鈕後面的位置?
謝謝大家!
Selenium只能複製用戶可以執行的操作。實際上,用戶不能與隱藏的元素進行交互。所以,如果不使用javascript,就不可能點擊隱藏的按鈕。
在情況下,如果你想用javascript:
JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element);
你可以這樣做:
public void foo(){
try{
button.click();
}catch(Exception e){
/**If I remember correctly, it will be an ElementNotVisible or ElementNotClickable Exception.
*
*Here you can move the circle element, possibly using a drag and drop
*method of the Actions class then click the element one more time.
*/
actions.dragAndDropBy(circleElement, xOffset, yOffset).perform();
button.click();
}
}
OR
public boolean foo(){
try{
button.click();
return true;
}catch(Exception e){
return false;
}
}
public void bar(){
if(!foo()){
actions.dragAndDropBy(circleElement, xOffset, yOffset).perform();
button.click();
}
}