Discover the invisible element using Selenium WebDriver in JavaScript by clicking on it

<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&</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&</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 attempting to click on Ship Order Console. Please refer to 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();

While printing ele.gettext(), it returns "sales order console", but upon clicking, it redirects to the inventory tab instead.

Could someone assist in identifying where the issue lies?

Answer №1

To set an attribute to a web element, you can refer to this link, How to use javascript to set attribute of selected web element using selenium Webdriver using java?

Another method is to click using Javascript without displaying it visibly. A CSS selector for the element has been used in this example.

executor.executeScript("$(\"div#divMenu2014>div\").click();");

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for transferring express route handling to the subsequent middleware and bypassing the current block of code

Here's the current setup of my route handler in my express app: app.use('/', function(res, req, next) => { if (!authorised) next(); f1(); f2(); }); Is there a way to prevent f1() and f2() from running without adding conditional st ...

The ajax function does not provide a response

Can you help me figure out why this JavaScript function keeps returning 'undefined'? I really need it to return either true or false. I've included my code below: function Ajax() { var XML; if(window.XMLHttpRequest) XML=new ...

What is the best method for retrieving a specific element nested within another element, employing a for loop and storing it in an array using JavaScript?

In my project, I was tasked with retrieving all the select and input elements that are nested within td elements in a table. My approach involved first fetching all the tds and storing them in an array. Then, I used a for loop to iterate through each td an ...

Complete Form Validation Issue Unresolved by Jquery Validation Plugin

I'm facing an issue with the jQuery validation plugin while attempting to validate a form. Strangely, it only works for one input field. Can anyone suggest a solution? <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.valid ...

angularsjs state provider with multiple parameters

I am struggling to create a state provider that can handle multiple parameters. Is it possible to capture them as an object or array, or do I have to capture them as a string and then separate them? For example, this is my current provider: .state(' ...

What is the best way to create an associative array using jQuery and then send it through AJAX to be parsed by PHP?

Is there a way to create an associative array in jQuery and send it via ajax to a php page for processing? Here is an example of what I am trying to achieve... // jQuery if($something == true) { data[alt] = $(this).attr('alt'); data[sr ...

Selenium encounters an unresponsive button without displaying any error message

Error Screenshot Whenever my code reaches the final line, it auto-clicks the convert button to change a YouTube music video into an mp3 file. However, only the website itself displays an "Invalid Argument" error below the button in a red box. I have exper ...

What is the process for updating a specific element in an object using Axios PATCH?

Using Axios.patch to modify data in an API. Here's a glimpse of the API structure: "email": "string", "phoneNumber": "string", "mobileNumber": "string", "temporaryAddress": { "address1": "string", "address2": "string", "address3": "string", " ...

Receiving the [object HTMLInputElement] on the screen rather than a numerical value

I have an input box where a user can enter a number. When they click a button, I want that number to be displayed on the page. However, instead of seeing the number, I am getting the output as [object HTMLInputElement]. Below is my TypeScript code: let qu ...

What steps can be taken to enable automatic playback for this slider?

After downloading the slider from this site, I've been attempting to enable autoplay on this slider but have not had any success. Can anyone provide guidance on how I can achieve this? I've tried modifying the code below without achieving the des ...

Blazor Dropdown Menus using <NavLink>

I'm currently working with the Blazor template that utilizes the NavLink component. It essentially incorporates Bootstrap menu functionalities under the hood. Although I've come across a few articles that discuss certain features like Matching, ...

Retrieving captcha image using Selenium in a web browser

Recently dipping my toes into Selenium and web scraping, I find myself struggling with captchas. Following the steps outlined in this post: Selenium downloading different captcha image than the one in browser I'm hitting a roadblock. Initial Hurdl ...

Using ng-model within ng-repeat for data binding in AngularJS

My challenge is to connect a model called 'User' to a series of input fields. Since I don't know the specific fields in advance, I need to write generic code that dynamically sets up the form based on the available fields. <script> ...

Tips for creating an Instagram photo collection on your own blog

Currently, I am on a quest to discover and either personalize or construct my very own Instagram photo gallery for the purposes of my personal blog website. The ownership of the website is fully mine which implies that I have the liberty to write PHP code ...

Error: The target container specified in the createRoot function is not a valid DOM element. Please check the container

I am currently utilizing React version 18.0.0 in my project, and I have encountered an error in my test file that appears as follows: createRoot(...): Target container is not a DOM element. The content of my test file is shown below: import ReactDOM fro ...

Is there a way to retrieve the URL response every time a new tab is opened?

I am currently working on a web scraping project where I am extracting data from the website Startup India, which serves as a platform for connecting with startups. My process involves selecting filters, clicking on each startup, and then delving into thei ...

Saving a variable within a for loop in JavaScript

Hey everyone, I could really use your help right now. Here's the code block I'm struggling with: function readyToSubmit(answerPack, answerArr, len) { for (var i = 0; i < answerArr.length; i++) { var questionId = answerArr[i].id; con ...

The custom validation in Node.js using Express-Validator is ineffective

I have implemented custom validators using express-validator to include specific validations: middlewares.js module.exports = function (app) { console.log('making sure I am being called'); return function (request, response, next) { ...

Tips for handling two JSON array objects with JavaScript

This particular function public function groups_priviledges($user_id = NULL){ $data['groups'] = $this->priviledges_model->admin_groups(); $data['member'] = $this->priviledges_model->empAdminGroup($user_id); echo ...

I am trying to showcase a collection of images on my homepage, but unfortunately, it is not functioning as expected

Does anyone know how to display images using Angular? I am currently utilizing the pic controller in an AngularJS file. Any assistance would be greatly appreciated. HTML CODE <!DOCTYPE html> <html> <head> <meta charset="utf-8"& ...