Java Selenium Webdriver:如何导航到子div并在特定div上移动foucs

Java Selenium Webdriver:如何导航到子div并在特定div上移动foucs,java,selenium,Java,Selenium,当前在导航到多个div标记时面临问题。 在我的应用程序中,我有一个网格,它填充或加载多个div标记中的数据 在鼠标悬停时,我必须单击添加注释选项,该选项将作为lightbox弹出窗口加载 请指导我如何选择添加评论选项 <div ng-cell=""> <div class="inCell ng-scope"> <div class="cellDarkGray" ng2-class="{cellDarkGray: (row.getProperty('returned

当前在导航到多个div标记时面临问题。 在我的应用程序中,我有一个网格,它填充或加载多个div标记中的数据

在鼠标悬停时,我必须单击添加注释选项,该选项将作为lightbox弹出窗口加载

请指导我如何选择添加评论选项

 <div ng-cell="">
<div class="inCell ng-scope">
<div class="cellDarkGray" ng2-class="{cellDarkGray: (row.getProperty('returnedRecordsNumber') != '0'),cellDarkGray: (row.getProperty('activityid') != '0'),cellDarkGray: (row.getProperty('returnedRecordsNumber') != '0')}">
<div class="cellOrange" ng-class="{cellRed: (row.getProperty('Impact') == '0'),cellOrange: (row.getProperty('activityid') != '0'), cellBlue: (row.getProperty('Impact') == '2')}"/>
<div class="cellWhite">
<div style="height:60px">
<div class="ng-hide" ng-show="(row.getProperty('commentFlag')== true) && (userRole =='ROLE_2') ">
<div class="ng-hide" ng-show="(row.getProperty('commentFlag')== true) && (userRole =='ROLE_1') ">
</div>
<div class="inCellData">
<div class="line1" ng-click="openDetails(row,'viewDetail')">
<span class="title1 ng-binding" ng-hide="row.getProperty('planned_typ')== 'NULL'">ORANGE PLANNED MAINTENANCE - </span>
<span class="title2 ng-binding" ng-hide="row.getProperty('deviceid')== 'NULL'">  BLCY810</span>
<!-- <span ng-hide="row.getProperty('myRouterName')== ''"> ||{{row.getProperty('myRouterName')}} ||</span> -->
</div>
<div class="line2">
<span class="title3"/>
<span class="ng-binding" ng-hide="row.getProperty('service_impact')== ''"> 1 - 5 MINS ||</span>
<span class="title3 ng-binding">09/JUN/2017 01:30:00 AM</span>
up to
<span class="title2 ng-binding">09/JUN/2017 03:30:00 AM</span>
|| 
<span class="ng-binding">EQUANT SHARED NETWORK</span>
</div>
<div class="line3">
</div>
<div>
<nav id="cbp-spmenu-s1" class="cbp-spmenu cbp-spmenu-vertical cbp-spmenu-left cbp-spmenu-open">
<a ng-click="openDetails(row,'viewDetail')">view details</a>
<div class="" ng-show="userRole =='ROLE_1'">
<a class="" ng-show="row.getProperty('internalFlag')=='Y'" ng-click="setUnsetInternal(row)">invisible to customer</a>
<a class="ng-hide" ng-show="row.getProperty('internalFlag')=='Z'" ng-click="row.getProperty('sourcesystem')=='Carrier Changes' && (row.getProperty('urgency')=='EMERGENCY' || row.getProperty('urgency')=='EXPEDITE') ? alertPastDataZEmergency() : alertPastDataZ() ">invisible to customer</a>
<a class="ng-hide" ng-show="row.getProperty('internalFlag')=='N'" ng-click="setUnsetInternal(row)">visible to customer</a>
<a class="ng-hide" ng-show="row.getProperty('internalFlag')=='X' || row.getProperty('internalFlag')=='H'" ng-click="alertPastDataX()">visible to customer</a>
</div>
<!-- Prod Consol Start -->
<a ng-show="userRole =='ROLE_1'" ng-click="openDetails(row, 'comment')">add a comment</a>
<!-- Prod Consol End -->
</nav>
</div>
</div>
</div>

橙色计划维修-
BLCY810
1-5分钟||
2017年6月9日01:30:00上午
高达
2017年6月9日03:30:00上午
|| 
等值共享网络
查看详细信息
顾客看不见
顾客看不见
对客户可见
对客户可见
添加评论

首先,您必须使用Action类将鼠标移动到元素,以便可以看到注释链接。然后必须对该元素执行操作

您可以这样做-

WebElement elem = driver.findElement(By.xpath("//a[contains(text(), 'add a comment')]"));

Actions action = new Actions(driver);
action.moveToElement(elem).click().build().perform();

希望这有帮助。

首先,您必须使用Action类将鼠标移动到元素,以便可以看到注释链接。然后必须对该元素执行操作

您可以这样做-

WebElement elem = driver.findElement(By.xpath("//a[contains(text(), 'add a comment')]"));

Actions action = new Actions(driver);
action.moveToElement(elem).click().build().perform();

希望这有帮助。将鼠标悬停在父元素上,使注释可见。下面的代码可能会给您一些想法

    Actions action = new Actions(driver);
    action.moveToElement("//nav[@id='cbp-spmenu-s1']").perform();

    //Now the comment button will be visible
    driver.findElement(By.xpath("//a[contains(text(), 'add a comment')]")).click();

希望这有帮助。谢谢。

将鼠标悬停在父元素上以使注释可见。下面的代码可能会给您一些想法

    Actions action = new Actions(driver);
    action.moveToElement("//nav[@id='cbp-spmenu-s1']").perform();

    //Now the comment button will be visible
    driver.findElement(By.xpath("//a[contains(text(), 'add a comment')]")).click();

希望这有帮助。谢谢。

我使用下面的代码解决了这个问题 WebElement we1=driver.findElement(By.xpath(//a[contains(text(),'adda comment'))][1]); JavascriptExecutor元素=(JavascriptExecutor)驱动程序;
elem.executeScript(“参数[0]。单击();”,we1)

我使用下面的代码解决了这个问题 WebElement we1=driver.findElement(By.xpath(//a[contains(text(),'adda comment'))][1]); JavascriptExecutor元素=(JavascriptExecutor)驱动程序;

elem.executeScript(“参数[0]。单击();”,we1)

//a[contains(text(),'add a comment')]检查此XPath感谢Santosh的回复。执行后出现以下错误错误消息:无法单击元素(警告:服务器未提供任何stacktrace信息)WebElement we1=GeneralActionKeywords.driver.findelelement(By.cssSelector(“.inCell.ng scope”);动作动作=新动作(GeneralActionKeywords.driver);WebElement we2=GeneralActionKeywords.driver.findElement(By.id(“cbp-spmenu-s1”);WebElement we3=GeneralActionKeywords.driver.findElement(By.xpath(“./*[@id='cbp-spmenu-s1']]/a[2]”);action.moveToElement(we2).moveToElement(we3).单击().build().perform();使用此逻辑访问,但有时会调用鼠标右键单击功能。您可以提供URL吗?它不在internet上托管。此链接仅在鼠标上方可见//a[contains(text(),'add a comment')]检查此XPath感谢Santosh的回复。执行后出现以下错误错误消息:无法单击元素(警告:服务器未提供任何stacktrace信息)WebElement we1=GeneralActionKeywords.driver.findelelement(By.cssSelector(“.inCell.ng scope”);动作动作=新动作(GeneralActionKeywords.driver);WebElement we2=GeneralActionKeywords.driver.findElement(By.id(“cbp-spmenu-s1”);WebElement we3=GeneralActionKeywords.driver.findElement(By.xpath(“./*[@id='cbp-spmenu-s1']]/a[2]”);action.moveToElement(we2).moveToElement(we3).单击().build().perform();使用此逻辑访问,但有时会调用鼠标右键单击功能。您可以提供URL吗?它不在internet上托管。此链接仅在鼠标上方可见,谢谢您的建议。我还是不行。你有什么错误吗。如果是,请粘贴.No error WebElement elem=GeneralActionKeywords.driver.findElement(By.xpath(//a[contains(text(),'adda comment')])));System.out.println(“hhhhhhhhh:+elem.getText());动作动作=新动作(GeneralActionKeywords.driver);action.moveToElement(elem).click().build().perform();当我尝试打印元素值时,当我检查System.out.println(“hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh,我在我的控制台里变假了。此标记被启用或仅在鼠标悬停时可见。谢谢您的建议。我还是不行。你有什么错误吗。如果是,请粘贴.No error WebElement elem=GeneralActionKeywords.driver.findElement(By.xpath(//a[contains(text(),'adda comment')])));System.out.println(“hhhhhhhhh:+elem.getText());动作动作=新动作(GeneralActionKeywords.driver);action.moveToElement(elem).click().build().perform();当我尝试打印元素值时,当我检查System.out.println(“hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh,我在我的控制台里变假了。此标记被启用或仅在鼠标悬停时可见。“获取错误”无法单击元素。我添加了如下代码Actions action=newactions(GeneralActionKeywords.driver);action.moveToElement(GeneralActionKeywords.driver.findelelement(By.xpath(“//nav[@id='cbp-spmenu-s1']”)).perform()//现在注释按钮将是可见的GeneralActionKeywords.driver.findElement(By.xpath(“./*[@id='cbp-spmenu-s1']]/a[2]”);注释按钮是否可见?GeneralActionKeywords.driveryes注释按钮的含义是可见的。我正在扩展其他类的驱动程序。WebElement we1=GeneralActionKeywords.driver.findElement(By.cssSelector(“.inCell.ng范围”);动作动作=新动作(GeneralActionKeywords.driver);WebElement we2=GeneralActionKeywords.driver.findElement(By.id(“cbp-spmenu-s1”);action.moveToElement(we2.perform();WebElement we3=GeneralActionKeywords.driver.findElement(By.xpath(