簡體   English   中英

懸停並使用Selenium WebDriver單擊隱藏元素

[英]Hover and click on hidden elements with Selenium WebDriver

當我開始使用Selenium時,我發現很難對隱藏的元素執行操作(懸停,單擊..etc等),僅當將鼠標懸停在其他元素上時,該操作才可見。 因此,我希望這對其他人有幫助,您可以使用以下任何一種方法。

例如,要upvote在此頁評論,我需要上下文(即注釋),使向上的箭頭可見盤旋,然后我需要點擊它。 但是,使用javascriptExcecuter可以一步執行。

//this can be used even if the element is not visible
//if you want to hover over the element, replace click() with hover() 
((JavascriptExecutor)driver).executeScript("$('element_selector').click();");

OR

you can use Actions class rather than using the Keyboard or Mouse directly. 
It implements the builder pattern: Builds a CompositeAction containing all actions specified by method calls

可以在這里找到有關Action類的更多信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM