2
<tr id="mytr">
   <td id="Table" onmouseover="this.className='menulevel1hl';" onmouseout="this.className='menulevel1norm'" class="menulevel1norm" onclick="PopupWin('Left',divMenu2011,this,'.menuitempopuprownormal','.menuitempopuprowhighlight','','.menuitempopupscroll' &nbsp;Alerts&nbsp </td>
      <div id=" divMenu2011 " name="actiondiv " style="visibility:hidden;position:absolute;border: ">
      <DIV  myonclick="window.parent.location.href='/smcfs/console/exception.search' ; "> Alert Search</DIV>
      </div>
   <td id="Table " onmouseover="this.className='menulevel1hl' ; " onmouseout="this.className='menulevel1norm' "  class="menulevel1norm " onclick="PopupWin( 'Left',divMenu2012,this, '.menuitempopuprownormal', '.menuitempopuprowhighlight', '', '.menuitempopupscroll'); "> &nbsp;Inventory&nbsp;</td>
   <div id="divMenu2012 " name="actiondiv " style="visibility:hidden;position:absolute;border: ">
      <DIV  myonclick="window.parent.location.href='/smcfs/console/inventoryaudit.search' ; ">  Inventory Audits</DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/inventory.detail?CurrentDetailViewID=YIMD080' ; "> Adjust Inventory</DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/itemsupsearch.search' ; "> Item Suppression Console</DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/additemsuppression.detail?CurrentDetailViewID=TGTOMSSCFD008' ; "> Add Item Suppression</DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/ProtectItem.detail?CurrentDetailViewID=TGTPID001' ; "> Add Protected Qty</DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/ProtectItem.search' ; "> Protected Qty Console   </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/ProtectItemAudit.search' ; ">    Protected Qty Audit Console </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/MCAFeeds.detail?CurrentDetailViewID=A001' ; ">   Upload MCA Store Feed </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/MCAFeeds.detail?CurrentDetailViewID=A002' ; "> Upload MCA Item Feed </DIV>
   </div>
   <td id="Table " onmouseover="this.className='menulevel1hl' ; " onmouseout="this.className='menulevel1norm' "  class="menulevel1norm " onclick="PopupWin( 'Left',divMenu2013,this, '.menuitempopuprownormal', '.menuitempopuprowhighlight', '', '.menuitempopupscroll'); "> &nbsp;RTAM Exclusion&nbsp; </td>
   <div id="divMenu201404150720371518959 " name="actiondiv " style="visibility:hidden;position:absolute;border: ">
      <DIV  myonclick="window.parent.location.href='/smcfs/console/Exclusion.detail?CurrentDetailViewID=D002' ; ">  RTAM Exclusion  </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/Exclusion.detail?CurrentDetailViewID=001' ; "> Start RTAM Exclusion  </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/Exclusion.detail?CurrentDetailViewID=D004' ; "> Remove  Excluded Items </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/Exclusion.detail?CurrentDetailViewID=D003' ; ">  Enter  Exclusion Removal </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/Exclusion.detail?CurrentDetailViewID=D009' ; "> Schedule RTAMExclusion   </DIV>
   </div>
   <td id="Table " onmouseover="this.className='menulevel1hl' ; " onmouseout="this.className='menulevel1norm' "  class="menulevel1norm " onclick="PopupWin( 'Left',divMenu2014,this, '.menuitempopuprownormal', '.menuitempopuprowhighlight', '', '.menuitempopupscroll'); ">     &nbsp;Sales Order&nbsp;   </td>
   <div id="divMenu2014 " name="actiondiv " style="visibility:hidden;position:absolute;border: ">
      <DIV  myonclick="window.parent.location.href='/smcfs/console/order.search' ; "> Sales Order Console   </DIV>
      <DIV  myonclick="window.parent.location.href='/smcfs/console/shipment.search' ; "> Outbound Shipment Console</DIV>
   </div>

I am trying to click on Ship Order Console. Please find the code below

WebElement ele1 = driver.findElement(By.xpath("//tr[@id='mytr']/td[4]"));
ele1.click();
WebElement ele = driver.findElement(By.xpath("//div[@id='divMenu2014']/div[1]"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript(js, ele); 
System.out.println("element is " + ele.getText());
ele.click();

When I am printing the ele.gettext(), I am getting "sales order console", but when I am trying to click on it it is moving to inventory tab.

Could any one point out where it is going wrong?

3
  • You can try WebElement ele = driver.findElement(By.xpath("//div[contains(@myonclick,'window.parent.location.href') and contains(text(),'Outbound Shipment Console')]"));ele.click(); Commented Oct 9, 2015 at 21:16
  • When you post HTML please take a minute to use a beautifier like jsbeautifier.org to properly format it. It makes it a LOT easier to read which makes your question more likely to get answered. Same goes for code. Please clean it up and properly indent it before posting. Thanks! Commented Oct 9, 2015 at 22:16
  • I am able to select the link with the above xpath.but when I am trying to click on the element it is moving to inventory..so want to know where the script went wrong Commented Oct 11, 2015 at 3:42

1 Answer 1

1

Check this link to set attribute to web element, How to use javascript to set attribute of selected web element using selenium Webdriver using java?

Alternatively, you can click using Javascript without making it visible. I have used CSS selector for your element.

executor.executeScript("$(\"div#divMenu2014>div\").click();");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.