如何上下文菜单 - 弹出菜单

如何上下文菜单 - 弹出菜单

问题描述:

点击我需要做到以下几点:如何上下文菜单 - 弹出菜单

1)右键单击一个元素

2)上下文菜单显示

3)在移动 在上下文菜单中的特定菜单(move_to_element) - 弹出
另一个菜单说MenuX

4)需要点击MenuX

我能够做的步骤1到3而不是4 当我检查is_displayed为MenuX返回False

当我尝试driver.find_element_by_xpath("html/body/div[5]/span[2]") 它的工作原理(我不想硬编码)。 但没有菜单的ID。

也试过,但没有运气
actions = ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()

我也试过driver.find_element_by_css_selector("div#contextMenu_Div #menuX")并没有奏效。 MenuX不是链接,而是一个span元素。

尝试使用下面的代码,以便右击后点击子菜单项:

WebElement element = driver.findElement("Find the element on which right click needs to be performed")); 

Actions actions = new Actions(driver).contextClick(element); 
WebElement mainMenu = driver.findElement(By.linkText("menulink")); 
actions.moveToElement(mainMenu); 

WebElement menuX = driver.findElement(By.cssSelector("subLinklocator")); 
actions.moveToElement(menuX); 
actions.click().build().perform(); 

希望这有助于

+0

感谢KARTHIK对于这个建议,但它没有帮助。 – Venu

你可以试试这个..

Actions actions = new Actions(driver); 
actions.contextClick(mainelement); 
actions.moveToElement(menuelement); 
actions.perform(); 

//at this point ur MenuX shd be visisble. 

driver.findElement("locator for ur MenuX").click();