1

I'm trying to select options from a dropdown, but it doesn't have the 'select' tag, so if I try to use the 'select' function in selenium it doesn't work. Then I tried following an example about clicking and using interactions like in the code below (I had to do the clicking that way because there's a message in the website that doesn't let me click objects in the normal way) but it doesn't work, the code runs, shows no errors, but doesn't select any option either.

WebElement ele1 = driver.findElement(By.xpath("//*[text()='- Select a Service -']"));
JavascriptExecutor executor1 = (JavascriptExecutor)driver;
executor1.executeScript("arguments[0].click();", ele1);
                    
Actions keyDown = new Actions(driver);
keyDown.sendKeys(Keys.chord(Keys.DOWN, Keys.DOWN)).perform();

Is there something wrong in my code? Or maybe you could tell me another way of selecting options from dropdowns when they don't have the 'select' tag.

Note: Below is an image of the dropdown code, it's the one in the bracket with the number '1'. The only thing to differentiate it from another dropdown is the title (the text within the red rectangle).

enter image description here

iag20
  • 73
  • 1
  • 4
  • It looks like the code you posted would open the pulldown and then try to hit the down arrow twice in the same instant. Even if it weren't a key chord, there's no enter key or click there. (and I think you want Keys.ARROW_DOWN if you're going to do it that way...) Better to just click the element you want after the options are opened. – pcalkins Aug 14 '20 at 18:53
  • I think I know what you mean. I changed the last part of the code with this: Actions keyDown = new Actions(driver); keyDown.sendKeys(Keys.ARROW_DOWN).click(); But it's still not working. Maybe the first part of clicking the dropdown is not working because I don't see that the dropdown is expanded, but I don't know another way of expanding it. And I don't recieve any error – iag20 Aug 14 '20 at 19:32

0 Answers0