【问题标题】:selenium - actions class- multiple actions not working硒 - 动作类 - 多个动作不起作用
【发布时间】:2019-10-16 19:24:31
【问题描述】:

我正在尝试在以下网站上选择第三级子菜单项。代码在此处执行时没有任何错误,但未在最终子菜单项上执行单击操作。

网址:https://www.bigbasket.com/

菜单项:Shop By Category -> Personal Care -> Ayurvedic

我在 chrome 浏览器上运行这个脚本。我试图选择二级菜单项,但是没有选择三级菜单项。顺便说一句,在 java 脚本执行器的帮助下,我能够成功地执行相同的操作。

Actions builder= new Actions(driver);

Action act=builder.moveToElement(driver.findElement(By.xpath(".//*[@id='navbar']/ul/li[1]/a")))             
                .moveToElement(driver.findElement(By.xpath("//a[@href='/cl/personal-care/?nc=nb']")))
                .moveToElement(driver.findElement(By.xpath("//a[@href='/pc/personal-care/ayurvedic-non-food/?nc=nb']")))

.click()
.build();

//perform() method when executing the Action object we designed above

act.perform();

【问题讨论】:

    标签: selenium action


    【解决方案1】:

    您需要在每个动作之后添加.build().perform(),因为所有“findElement”方法都在新动作的开始处运行。并执行“perform()”让他们再次搜索

    【讨论】:

    • 没有解决问题..它只是像以前一样导航,但不模拟点击操作。 bigbasket.com 是示例网站,如果您想尝试一下 menu1-->menu2-->menu3
    【解决方案2】:

    试试下面的,

    Actions builder= new Actions(driver);

    Action act=builder.moveToElement(driver.findElement(By.xpath(".//*[@id='navbar']/ul/li[1]/a")))
    .moveToElement(driver.findElement(By.xpath("//a[@href='/cl/personal-care/?nc=nb']"))) .click(driver.findElement(By.xpath("//a[@href='/pc/personal-care/ayurvedic-non-food/?nc=nb']")))
    
    .build();
    
    act.perform(); 
    

    【讨论】:

    • 没有解决问题..它只是像以前一样导航,但不模拟点击操作。 bigbasket.com 是示例网站,如果您想尝试一下 menu1-->menu2-->menu3
    猜你喜欢
    • 2018-08-27
    • 1970-01-01
    • 2011-02-02
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多