如何从胡佛菜单Selenium JAVA打开WebElement [英] How to open a WebElement from a Hoover Menu Selenium JAVA

查看:125
本文介绍了如何从胡佛菜单Selenium JAVA打开WebElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的代码:

  System.setProperty(webdriver.gecko.driver,C:\\DRIVERS\\geckodriver.exe); 
WebDriver driver = new FirefoxDriver();
//打开门户财政
driver.get(http://150.23.110.111/Retenciones/);
//查找字段并输入用户名和密码
driver.findElement(By.id(frmLogin:txtUsr))。sendKeys(arrubio);
driver.findElement(By.id(frmLogin:txtPwd))。sendKeys(gnp00gnp);
driver.findElement(By.id(frmLogin:butLogin))。click();
Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath());
action.moveToElement(we).moveToElement(driver.findElement(By.xpath()));

我可以毫无问题地进入页面,我可以输入用户名和密码登录,但在下一页有一个胡佛菜单,我不能使用它,并停止自动执行。



这是xpath和csspath:



xpath:/ html / body / div [3] / div / div / form / div / ul / li [1] / ul / li [1] / a / span



csspath:html body div#content div#leftPanel.ui-layout-unit.ui-widget.ui-widget-content.ui-corner-all.ui-layout-west.blankBck div.ui-layout-unit-content.ui-widget-content form#j_id1833690111_27e067e8.blankBck div#j_id1833690111_27e067e8:j_id1833690111_27e0678e.ui-menu.ui-menubar.ui-widget.ui-widget-content.ui-corner-all。 ui-helper-clearfix ul.ui-menu-list.ui-helper-reset li.ui-widget.ui-menuitem.ui-corner-all.ui-menu-parent.ui-menuitem-active ul.ui-widget -content.ui-menu-list.ui-corner-all.ui-helper-clearfix.ui-menu-child.ui-shadow li.ui-menuitem.ui-widget.ui-corner-all a.ui-menuitem -link.ui-corner-all span.ui-menu item-text

这是检查Búsqueda按钮的元素。

 < ul class =ui-widget-content ui-menu-list ui-corner-all ui-helper-clearfix ui-menu-child ui-阴影角色=菜单style =显示:块;身高:自动; z-index:1013; left:0px; top:28px;>< li class =ui-menuitem ui-widget ui-corner-allrole =menuitem>< a class =ui-menuitem-link ui-corner-allhref =/ Retenciones / main / faces / m_evaPuntual.xhtmlstyle =width:120pxtabindex = -  1>< span class =ui-menuitem-text>Búsqueda< / span>< a>< / li>< li class =ui-menuitem ui-widget ui-corner-allrole =menuitem>< / ul>  

如何从hoover菜单中选择并打开按钮Búsqueda?

感谢您的关注:)

解决方案

试用:

  Actions action = new Actions(driver); 
WebElement menu = driver.findElement(By.xpath(xpath for menu));
WebElement item = driver.findElement(by.cssSelector(Búsqueda的css选择器值));
action.moveToElement(menu).moveToElement(item).click()。build()。perform();


Hello I'm new using selenium and I was trying to execute some tests from a web page.

This is my code:

 System.setProperty("webdriver.gecko.driver","C:\\DRIVERS\\geckodriver.exe");
    WebDriver driver = new FirefoxDriver();
    //Open Portal Fiscal
    driver.get("http://150.23.110.111/Retenciones/");
    //Find what field and enter the user and password
    driver.findElement(By.id("frmLogin:txtUsr")).sendKeys("arrubio");
    driver.findElement(By.id("frmLogin:txtPwd")).sendKeys("gnp00gnp");
    driver.findElement(By.id("frmLogin:butLogin")).click();
    Actions action = new Actions(driver);
    WebElement we = driver.findElement(By.xpath(""));
    action.moveToElement(we).moveToElement(driver.findElement(By.xpath("")));

I can enter to the page without problem and I can enter the user and the password to login, but there's a hoover menu on the next page that I can´t use and stops my automatic execution.

This is the xpath and the csspath:

xpath: /html/body/div[3]/div/div/form/div/ul/li[1]/ul/li[1]/a/span

csspath: html body div#content div#leftPanel.ui-layout-unit.ui-widget.ui-widget-content.ui-corner-all.ui-layout-west.blankBck div.ui-layout-unit-content.ui-widget-content form#j_id1833690111_27e067e8.blankBck div#j_id1833690111_27e067e8:j_id1833690111_27e0678e.ui-menu.ui-menubar.ui-widget.ui-widget-content.ui-corner-all.ui-helper-clearfix ul.ui-menu-list.ui-helper-reset li.ui-widget.ui-menuitem.ui-corner-all.ui-menu-parent.ui-menuitem-active ul.ui-widget-content.ui-menu-list.ui-corner-all.ui-helper-clearfix.ui-menu-child.ui-shadow li.ui-menuitem.ui-widget.ui-corner-all a.ui-menuitem-link.ui-corner-all span.ui-menuitem-text

And this is the element that appears inspecting the "Búsqueda" button.

<ul class="ui-widget-content ui-menu-list ui-corner-all ui-helper-clearfix ui-menu-child ui-shadow" role="menu" style="display: block; height: auto; z-index: 1013; left: 0px; top: 28px;">
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
<a class="ui-menuitem-link ui-corner-all" href="/Retenciones/main/faces/m_evaPuntual.xhtml" style="width:120px" tabindex="-1">
<span class="ui-menuitem-text">Búsqueda</span>
</a>
</li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
</ul>

How can I select and open the button "Búsqueda" from the hoover menu?

Thanks for the attention :)

解决方案

try using:

Actions action = new Actions(driver);
WebElement menu = driver.findElement(By.xpath("xpath for menu"));
WebElement item = driver.findElement(by.cssSelector("css selector values for Búsqueda"));
action.moveToElement(menu).moveToElement(item ).click().build().perform();

这篇关于如何从胡佛菜单Selenium JAVA打开WebElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆