-1

Html is as below :

<label id="choose" for="options">01</label>

I am getting this exception when i tried to send value for this field.

Code I used :

driver.findElement(By.xpath("//*[@id=\"choose\"]")).sendKeys("01");

Also tried :

Select hr=new Select(driver.findElement(By.id("choose")));
hr.selectByValue("04");
  • 2
    The exception is pretty much self explanatory, Selenium is expecting a Select tag but you are passing a label tag.You can share your HTML so we can help you with the problem you have. – Nikolay Barakov Feb 22 at 11:09
1

If something looks like a select dropdown, it does not mean it uses a real select HTML element.

The new Select() object only works for real select elements, not labels, or lists of labels. If you feed it a label element you will get that error in your title.

The label with id choose is not something you can use as input, it is just a static label with the text 01. You cannot sendkeys to a static element. Probably it is inside some other elements that handle the input. Maybe you can try to click on the label to select it?

I suggest you talk the developers and ask how the selection of input works and which element should get the input. If you cannot reach the developers, maybe a HTML/CSS/JS training would help.

0

As Niels van Reijmersdal already answered, the error in question is due to the fact that the element you are trying to automate is a label(a static element that just displays text) and it is not a select element or even an input element which you can interact with. Therefore, both the codes you used would throw some error since you are trying to input in a label field.

Another point I would like to add is, from the HTML for the label, I can see that it is a label for an element with id 'options'. I guess that might be the Select element you are trying to automate.

This code might work in your case but you need to provide some more code, at least for the element with the id='options' for us to be able to help.

Select hr=new Select(driver.findElement(By.id("options")));
hr.selectByValue("04");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.