0

I know this question has been asked plenty of times, I have tried all of the solutions that were on the other threads but I cannot get any to work, so hopefully someone can help here.

I am writing a Selenium test case and I have it working so far up to this problem. I think this should be very basic and easy to do, but for some reason I just can't get it to work. I am trying to select a value in a drop down list but I keep getting the following error when I try to select the value either by ID, XPath or link. This is the error -

Unable to locate element: {"method":"xpath","selector":".//*[@id='value_3']/a"}

This is my code for finding the element -

webdriver.findElement(By.xpath(".//*[@id='value_3']/a"));

Would anyone have any suggestions to try? I have also tried putting in a timer to ensure that everything is loaded on the page by doing this -

webdriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);      

but I still get the same error.

8
  • Which solutions have you tried? Commented Mar 21, 2016 at 9:22
  • @FlorentB. Do you want me to paste in the links here or code? I have tried it by selecting the XPath of the element, the ID, getText and the link. I googled my question and tried all of the solutions that came up. The solution should be very simple but I can't get it to work. Commented Mar 21, 2016 at 9:28
  • Have you checked if it's inside a frame? Commented Mar 21, 2016 at 9:29
  • @FlorentB. yes, I checked using Firepath and there's no frame code inside the file. Commented Mar 21, 2016 at 9:35
  • Can you provide the HTML? At least the concerned part. Commented Mar 21, 2016 at 9:37

3 Answers 3

1

Your xpath is wrong. the link has the id, so your path was looking for yet another link. try:

webdriver.findElement(By.xpath(".//a[@id='value_3']"));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply @Breaks Software but I had tried that before and the same problem persists. I have no idea how to try and fix this, I'm having the same problem when I try to select a value from a pop up modal.
Please show us the HTML for the entire menu, your selenium code to open the top menu then choose the menu item, and the error message that you get when you run this selenium code. This is the best way we can help you.
0

You could try the "dirty way", as in: download Firefox, install the Selenium IDE plugin, record yourself performing this specific action and then see what output IDE generates. Try using this. If this doesn't work either, it is probable/possible the dropbox is in a different frame.

5 Comments

Thanks, I was using the IDE initially and it worked that way when I changed a few things (i.e. a command from click to doubleClick) but since I have rewrote the test case in Eclipse it is constantly failing at this one part.
Could you try locating the element by id and checking what happens?
Yeah I tried that through the IDE and it says the same thing - that the element ID has not been found. The only way I can get it to work through the IDE is by saying link=User Name for Target. It won't work when I try that way in Eclipse.
And did you try switching frames as well?
Sorry, I'm not exactly sure what you mean, there is no frame code in the HTML if that is what you mean? So I don't have anything in my code relating to frames.
0

new Select(driver.findElement(By.xpath(".//*[@id='value_3']/a"))).selectByvisibletext("your preferred text");

you can user selectByvalue.

for Wait: user thread.sleep(1000);

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.