java编写鼠标悬停在二级菜单,点击三级菜单?
目前遇到的问题:我想点击一个三级菜单,需要做的操作是,鼠标悬停在菜单按钮上,此时弹出二级菜单,鼠标再次悬停在某二级菜单上,弹出三级菜单,然后点击某三级菜单当前问题:总是提...
目前遇到的问题:我想点击一个三级菜单,需要做的操作是,鼠标悬停在菜单按钮上,此时弹出二级菜单,鼠标再次悬停在某二级菜单上,弹出三级菜单,然后点击某三级菜单
当前问题:总是提示找不到二级菜单的元素
@Test
public void testcase5() throws Exception{
Thread.sleep(5000);
//鼠标悬浮在“菜单”icon上
WebElement Meau=driver.findElement(By.xpath("//*[@id=\"fixedBar\"]/div/div[1]/span"));
Actions action=new Actions(driver);
//鼠标移动到“菜单”icon上方
action.moveToElement(Meau).perform();
Thread.sleep(5000);
//鼠标移动到弹出的“云安全”菜单上方
WebElement YunAQ=driver.findElement(By.xpath("/html/body/div[5]/div/div/section/aside/ul/li[3]/div"));
action.moveToElement(YunAQ).perform();
Thread.sleep(5000);
//点击弹出的“DDOS云清洗”
WebElement DDOS=driver.findElement(By.xpath("/html/body/div[4]/ul/li[1]/div"));
action.moveToElement(DDOS).click().perform();
Thread.sleep(3000);
执行结果:org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/ul/li[1]/div"}
总是提示找不到二级菜单中的那个元素 展开
当前问题:总是提示找不到二级菜单的元素
@Test
public void testcase5() throws Exception{
Thread.sleep(5000);
//鼠标悬浮在“菜单”icon上
WebElement Meau=driver.findElement(By.xpath("//*[@id=\"fixedBar\"]/div/div[1]/span"));
Actions action=new Actions(driver);
//鼠标移动到“菜单”icon上方
action.moveToElement(Meau).perform();
Thread.sleep(5000);
//鼠标移动到弹出的“云安全”菜单上方
WebElement YunAQ=driver.findElement(By.xpath("/html/body/div[5]/div/div/section/aside/ul/li[3]/div"));
action.moveToElement(YunAQ).perform();
Thread.sleep(5000);
//点击弹出的“DDOS云清洗”
WebElement DDOS=driver.findElement(By.xpath("/html/body/div[4]/ul/li[1]/div"));
action.moveToElement(DDOS).click().perform();
Thread.sleep(3000);
执行结果:org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/ul/li[1]/div"}
总是提示找不到二级菜单中的那个元素 展开
展开全部
import java.awt.*;
import javax.swing.*;
public class ErjiMenu extends JFrame
{
JPanel jp=new JPanel();
JMenuBar menubar=new JMenuBar();
JMenu m1=new JMenu("菜单");
JMenu m2=new JMenu("菜单");
JMenuItem item1=new JMenuItem("菜单项");
JMenuItem item2=new JMenuItem("菜单项1");
JMenuItem item3=new JMenuItem("菜单项2");
public ErjiMenu()
{
jp.setLayout(new BorderLayout());
m2.add(item2); //m2添加菜单项。
m2.add(item3);
m1.add(item1);
m1.add(m2); //m1把m2添加进去,作为二级菜单.
menubar.add(m1);
jp.add(menubar,BorderLayout.NORTH);
this.add(jp);
this.setBounds(100,100,380,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new ErjiMenu();
}
}
不用JPopupMenu,更简单。
import javax.swing.*;
public class ErjiMenu extends JFrame
{
JPanel jp=new JPanel();
JMenuBar menubar=new JMenuBar();
JMenu m1=new JMenu("菜单");
JMenu m2=new JMenu("菜单");
JMenuItem item1=new JMenuItem("菜单项");
JMenuItem item2=new JMenuItem("菜单项1");
JMenuItem item3=new JMenuItem("菜单项2");
public ErjiMenu()
{
jp.setLayout(new BorderLayout());
m2.add(item2); //m2添加菜单项。
m2.add(item3);
m1.add(item1);
m1.add(m2); //m1把m2添加进去,作为二级菜单.
menubar.add(m1);
jp.add(menubar,BorderLayout.NORTH);
this.add(jp);
this.setBounds(100,100,380,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new ErjiMenu();
}
}
不用JPopupMenu,更简单。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询