Tips for Choosing an Option Using Selenium

Can someone please assist me?

I am having trouble selecting an element because when I hover/click on the dropdown id='rfdSubMenu1396697749612', it becomes visible. If I move the cursor away, it becomes hidden.

However, when I try to run the code below, I get an error saying 'No such element id='rfdSubMenu1396697749612''. How can I make it visible and select an option?

The junit code was generated from Selenium IDE

    driver.findElement(By.id("ctl00_InventoryContent_btnAddSystem")).click();
    driver.findElement(By.id("ctl00_InventoryContent_txtAssetName")).clear();
    driver.findElement(By.id("ctl00_InventoryContent_txtAssetName")).sendKeys("ASDE346");
    driver.findElement(By.id("ctl00_InventoryContent_txtControlNumber")).clear();
    driver.findElement(By.id("ctl00_InventoryContent_txtControlNumber"))
        .sendKeys("ASDE346");
    driver.findElement(By.cssSelector("span.rfdSelectText")).click();
    driver.findElement(By.xpath("//div[@id='rfdSubMenu1396538734351']/ul/li[2]")).click();
    new Select(driver.findElement(By.id("ctl00_InventoryContent_ddlAssetType")))
         .selectByVisibleText("Networking");
    driver.findElement(By.cssSelector("#Skinnedctl00_InventoryContent_ddlAssetStatus > span.rfdSelectOuter > span.rfdSelectText")).click();
    driver.findElement(By.xpath("//div[@id='rfdSubMenu1396538761911']/ul/li[3]")).click();
    new Select(driver.findElement(By.id("ctl00_InventoryContent_ddlAssetStatus"))).selectByVisibleText("InActive");

Changes Made in Junit code

driver.findElement(By.cssSelector("span.rfdSelectText")).click();
// Next line causes 'No such Element Present' Error
WebElement dis = driver.findElement(By.cssSelector("html.RadForm body div#rfdSubMenu1396685935145.rfdSelectBox"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("rfdSelect_selected.click()" , dis);
new Select(driver.findElement(By.id("ctl00_InventoryContent_ddlAssetStatus"))).selectByVisibleText("InActive");

HTML CODE

<div id="rfdSubMenu1396697749612" class="rfdSelectBox rfdSelectBox_Default" 
style="overflow-y: auto; width: 149px; position: absolute; visibility: hidden; left: 
885px; top: 277px; display: none;">

Answer №1

Just like karna pointed out, there must be a specific event that triggers the display of the drop-down menu. Have you copied and pasted the exact HTML code? It's possible that there is a hover or click event required to activate the dropdown. You could experiment with utilizing a click() event:

new WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.id("industryType"))).click();
new WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#industryType option[value='Nt']"))).click();
new WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#industryType option[value='Nt']"))).click();

Answer №2

Executing a series of actions using the Actions class in Selenium WebDriver, we can first create an instance of this class as 'act'. Then we utilize the moveToElement method to move the mouse pointer to a specific element located by its XPath. Finally, we perform a click action on that element.

Answer №3

One common issue encountered in Selenium is when an element is not visible, preventing interaction with it. It's important to ensure that the element is visible or trigger an event that makes the dropdown appear on the screen.

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

Issue with jsPDF rendering Japanese characters when printing

I am having trouble generating a PDF with Japanese characters こんにちは However, when I view the printed PDF, it shows these characters instead: þÿ0S0“0k0a0o A similar issue was raised in a previous query regarding JsPDF not supporting Japa ...

ng2-idle server side rendering problem - Uncaught ReferenceError: document is undefined

Can ng2-idle be used for idle timeout/keepalive with pre-rendering in Angular 4? I followed this link for implementation: It works fine without server pre-rendering, but when I add rendering back to my index.html, I keep getting the following error: Exce ...

Utilize environment variables to access system information when constructing an Angular 2 application

In order to build my Angular application, I want to utilize a single system variable. System Variable server_url = http://google.com This is how my Environment.ts file looks: export const environment = { production: false, serveUrl: 'http://so ...

Getting data from each row in a column of Excel using Python with Selenium, xlrd, and Pandas

I am currently working on a project that involves extracting data from an excel file and then inputting it into a field on our company's website. The excel spreadsheet is structured like this: [Column A] [Column B] Zach 1111 Chris 222 ...

Tips for distributing a Vue plugin on NPM

I developed a straightforward plugin for Voca.js using Typescript. The source code can be found here. index.ts import VueVoca from './vue-voca'; export { VueVoca }; vue-voca.ts import vue from 'vue'; export default { install( ...

Show image when hovering over individual words

Is there a way to display different descriptions or images when hovering over each word in a paragraph using HTML? It seems that only the last element is being retrieved and displayed across the entire paragraph. Any suggestions on how to fix this issue wo ...

Initiate navigation in AngularJS through routing

My AngularJS app has a reset link that I need to use to reset it... <a ng-click="resetApp()">reset</a> The button press is being handled in the main controller... $scope.resetApp = function(){ if(confirm("You will lose data...")){ ...

Encountering an error while trying to install npm formidable

Having some trouble installing the formidable JS library. It appears that https://registry.npmjs.org/formidable is currently down. I used isup.me and it seems like the registry site is completely down. Can anyone confirm if this is the issue or if there ma ...

Tips on maintaining the color of the favorite / unfavorite button even after refreshing the page

I am currently developing a Laravel project that allows users to favorite and unfavorite books. When a user clicks on the favorite button, the color changes to red. If clicked again, the color reverts back to gray. The database successfully updates without ...

What did I overlook in my AJAX implementation?

When a user selects a value from the dropdown menu, an Ajax call must be made to the server to retrieve some values in JSON format. Below is the Ajax code //AJAX Security $('#ddlSecurityLevel').change(function () { if ($('#ddlSecurityL ...

Reply after performing several asynchronous queries using mongoose and express

When trying to create a list of products to send to a client, I am encountering an issue where res.send executes before the loop has completed. I have tried using async/await but it doesn't seem to work. Any suggestions on how to resolve this? Below ...

Enable retrieval of calculated time duration in jQuery time picker

After implementing two separate timepickers for calculating a time duration, I am looking to access this computed duration for further calculations later on the page. How can I retrieve the duration that is already displayed to the user after using the sec ...

JavaScript Ext is not declared

I've designed a webpage with tabs, and everything was working fine in our development environment. However, when we moved it to the staging environment, we started experiencing errors this morning that I'm not sure how to resolve as my JavaScript ...

Changing the names of object keys in JavaScript by utilizing a conversion object

Let's dive right in: I have a list of countries along with their respective values: { Mainland China: 14375, Japan: 20, Thailand: 19, Singapore: 18, South Korea: 15, Hong Kong: 14, Taiwan: 10, Germany: 8, Malaysia: 8, Macau: 7, France: 6, Vietnam: 6 ...

Creating an express route for updating with various parameters: a step-by-step guide

I am trying to make an update to a specific attribute in a JSON object by using the fetch PUT method. I have set up a put function that takes in 2 URL parameters app.put('/trustRoutes/:id/:item', (req, res){ So far, I have been able to update t ...

Utilizing JavaScript and PHP to dynamically load HTML content on a webpage

Below is the code snippet I'm working with: <?php if ($x == 1){ ?> <b>Some html...</b> <?php } else if ($x==2){ ?> <b> Other html...</b> <?php } ?> Now, I want to create two links (a ...

"Enhance your Material-UI ListItems with dynamic ripple colors when using React-Router NavLink

Currently, I am attempting to nest a Material-UI <ListItem button> within a react-router <NavLink>. While functionality is present, I have observed that the ripple colors on the <ListItem button> are being altered by the <NavLink> C ...

I need help determining the starting date and ending date of the week based on a given date

I am looking to determine the starting date (Monday) and ending date of a specified date using Javascript. For instance, if my date is 2015-11-20, then the starting date would be 2015-11-16 and the ending date would be 2015-11-21. ...

Experiencing difficulties establishing a connection between the React client and Node.js server using SocketIO

I am currently getting familiar with socketIO and have successfully set up a basic nodejs server. However, I am facing an issue where my nextJS app is unable to connect to the server as expected. Despite no errors being displayed, the messages that should ...

Instructions on how to refresh a FullCalendar component in Vue.js

I am currently using the fullCalendar library for vuejs and facing an issue where I need to refresh the component after deleting an event. <div> <FullCalendar :key="componentKey" v-model="FullCalendar" locale="es" :plugins="calen ...