How to choose a javascript drop down using selenium?

Here is the HTML code for a JavaScript drop-down menu that contains various options, including "All Resumes". I am attempting to select this option using Selenium WebDriver:

<div id="resume_freshness_container">
<div class="dropdown_small_wrapper">
<div class="left">Last 6 Months</div>
<div class="right"><img class="clip_image" src="http://media.monsterindia.com/v2/recruiter/2.1/new_search/newlook_combined.png"></div>
<div class="clear_both"></div>
</div></div>
<script language="javascript">  
jQuery(document).ready(function(){  
createSingleSelectCombo({id:'selDay',valueVariableName:'day',tabindex:'62',label:"",preSelected:"180",replaceWithId:'resume_freshness_container',width:'216',heightOptions:'height:240px;overflow-y:auto',animateScroll:true,
options:[{id:'1',values:"in last 1 day"},
{id:'3',values:"in last 3 days"},               
{id:'7',values:"in last 7 days"},               
{id:'15',values:"in last 15 days"},             
{id:'30',values:"in last 1 month"},             
{id:'90',values:"in last 3 months"},                
{id:'180',values:"in last 6 months"},               
{id:'360',values:"in last 12 months"},              
{id:'540',values:"in last 18 months"},
{id:'9999',values:"All Resumes"},
{id:'4-7',values:"4-7 days"},
{id:'8-15',values:"8-15 days"},
{id:'16-30',values:"16-30 days"},
{id:'31-90',values:"1-3 months"},
{id:'91-180',values:"3-6 months"},
{id:'181-360',values:"6-12 months"},
{id:'361-540',values:"12-18 months"},
{id:'541-9999',values:"Only older than 18 months"}

]});


borderTopSingleSelect({container:'resume_freshness_container',afterId:'10'});

});


</script>   

In my Selenium code, I am attempting to select the desired option from the drop-down menu:

Select select = new Select(driver.findElement(By.id("resume_freshness_container")));
select.deselectAll();
select.selectByVisibleText("All Resumes");

I have also tried selecting it by id "selDay", but I encountered the following exception both times:

Exception in thread "main" org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"

*As a beginner in Selenium, I would greatly appreciate any guidance on where I may have gone wrong.*

Answer №1

It's important to note that the Select class is designed specifically for handling select->option HTML structures, so approaching it this way won't work.

To properly interact with the element, you should first find the element with the id="selDay", then click on it. After that, locate the element containing the text "All Resumes" and click on it:

WebElement selDay = driver.findElement(By.id("selDay"));
selDay.click();

WebElement allResumes = selDay.findElement(By.xpath("//*[.=\"All Resumes\"]"));
allResumes.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

Getting the text from an element following the utilization of driver.find_elements_by_id

Currently, I am attempting to extract the information from a table by following these steps: from selenium import webdriver driver = webdriver.Chrome() driver.get("https://fortnitetracker.com/events/epicgames_S11_CC_Contenders_EU") player = driver.find_ ...

Java Chatclient with a User-Friendly HTML Interface

My team is embarking on a new project involving the development of a Chatclient to be integrated into a webapp. Our requirements include: - Java server - Java client We have nearly completed coding both the client and server, but now we face the challe ...

retrieve information provided by the user

When a user inputs a date into #dateUserInput and clicks the button, I want the fetch function to retrieve the appropriate image for that date. However, an error occurs: VM113:1 Uncaught (in promise) SyntaxError: Unexpected end of JSON input at getimag ...

Attempting to create a multi-page slider using a combination of CSS and JavaScript

Looking for help with creating a slider effect that is triggered when navigating to page 2. Ideally, the div should expand with a width of 200% or similar. Any assistance would be greatly appreciated! http://jsfiddle.net/juxzg6fn/ <html> <head& ...

Python - Selenium webdriver throwing an error after being executed for an extended period

I have a BOT running on a cloud machine (AWS 1GB instance) using selenium-webdriver + pyvirtualdisplay. The script is performing repetitive tasks in a loop that iterates 50000 times. However, it stopped working at the 1016th iteration, and an error occurr ...

Is it feasible to retrieve and view local storage data within an Electron application?

I created an electron application that enables users to drag and drop elements like divs on the screen, saving their positions in localstorage as a class. The purpose is to ensure that any modifications made by the user persist even after reloading or re ...

Supporting server-side routing with NodeJS and Express for AngularJS applications

My current setup includes NodeJS + expressJS on the server and AngularJS on the client side. The routes defined in my AngularJS controller are as follows: app.config(function($routeProvider,$locationProvider) { $routeProvider .when('/field1/:id&apo ...

What is the benefit of storing an IIFE in a variable?

When it comes to using IIFE in JavaScript and AngularJS, I have come across two common structures: Structure 1: //IIFE Immediately Invoked Function Expression (function () { }()); However, there is another structure where the IIFE is assigned to a var ...

Execute the testng.xml file through the Terminal on a MacBook

Struggling to run testng.xml on my Mac. I've attempted the steps multiple times, but keep running into the error message "Error: Could not find or load main class org.testng.TestNG" I can run testng.xml from Eclipse, but I'm unable to do it fro ...

ReactJS is encountering a situation where two children are using the same key and causing

When I try to view the profile information of another user, I encounter a duplicate key error that says: "Warning: Encountered two children with the same key, ``. Keys should be unique so that components maintain their identity across updates. Non-unique k ...

Arrow functions do not function properly with Typescript decorators

I've created a typescript decorator factory that logs the total time taken to execute a function, along with the actual function execution results and parameters passed to the decorator. For example: export function performanceLog(...args: any[]) { ...

Updating is not happening with ng-repeat trackBy in the case of one-time binding

In an attempt to reduce the number of watchers in my AngularJS application, I am using both "track by" in ngRepeat and one-time bindings. For instance: Here is an example of my view: <div ng-repeat="item in items track by trackingId(item)"> {{ : ...

Trigger a jQuery modal by clicking on a cell within a table

As a novice in jquery, I am facing a challenge. I have a table with a column showing the total number of employees in a department. When a user clicks on this column, it should open up a jquery modal displaying a list of employees like EmpA, EmpB, and Em ...

Preserve the existing value and then check it against the updated value of a variable within JavaScript

I utilized an API that supplies me with information in JSON format, retrieved the price of a specific currency, and presented it on a screen using JavaScript. I encapsulated this process within a function that dynamically updates the information at set int ...

How can I use Selenium RC with Ruby to wait for a hidden element to appear?

What is the best way to wait for a hidden element to appear on the webpage? I attempted to use seleum.is_element_present but it doesn't seem to be effective. ...

Sharing socket data between different namespaces in Socket.ioSocket.io enables the

Is there a solution to sharing data set in a socket in one namespace and accessing it on another namespace? While I understand that data can be attached to the socket object itself, a problem arises when trying to access the data in a different namespace. ...

Optimal method for file uploading with Node.js

How can I effectively manage file uploads in node js? I would like users to be able to upload profile images with the following specifications: -Validated size of at least 200 * 200 -Accepted file formats are png, jpg, jpeg, or gif -Additional functi ...

Guide to creating standalone Express middleware that can interact with the raw request body

Can anyone help me with writing an Express middleware that can access the raw request body without affecting other handlers or middlewares? I want to achieve something like this: const middleware = [ express.raw({ type: '*/*' }), (req, res, n ...

generating a new item using Mongoose searches

How can I generate an object based on queries' results? The table in the meals operates using database queries. How do I handle this if the queries are asynchronous? const getQueryResult = () => { Dinner1300.count().exec(function (err, count) ...

What is the best way to find the maximum and minimum values within a JSON object that is populated from user inputs using only JavaScript?

Here is a simple form that stores data at the following link: https://jsfiddle.net/andresmcio/vLp84acv/ var _newStudent = { "code": code, "names": names, "grade": grades, }; I'm struggling to retrieve the highest and lowe ...