0

我有一个这样的菜单下拉菜单。使用 selenium 我需要移动菜单,但可以通过 ID、xPath 等检索元素。请你帮忙

<td id="140#200" nowrap="" class="k140" onclick="menuclic(&quot;140&quot;,this,&quot;#200&quot;)" onmousedown="menudown(&quot;140&quot;,this)" onmouseup="menuup(&quot;140&quot;,this)" onmousemove="menumousemove(&quot;140&quot;,this,'#200')" onmouseover="menuover(&quot;140&quot;,this)" onmouseout="menuout(&quot;140&quot;,this)">&nbsp;Suivi&nbsp;des&nbsp;réclamations&nbsp;</td>
4

1 回答 1

0

你可以像这样处理这个问题。当然,这只是一个例子。

//Instantiate Action Class        
Actions actions = new Actions(driver);
//Retrieve WebElement 'Music' to perform mouse hover 
WebElement menuOption = driver.findElement(By.xpath(".//div[contains(text(),'Music')]"));
//Mouse hover menuOption 'Music'
actions.moveToElement(menuOption).perform();
System.out.println("Done Mouse hover on 'Music' from Menu");

//Now Select 'Rock' from sub menu which has got displayed on mouse hover of 'Music'
WebElement subMenuOption = driver.findElement(By.xpath(".//div[contains(text(),'Rock')]")); 
//Mouse hover menuOption 'Rock'
actions.moveToElement(subMenuOption).perform();
System.out.println("Done Mouse hover on 'Rock' from Menu");

生成的图像是:

这里.

于 2020-02-26T10:01:45.227 回答