Element should have been “select” but was “div” getting an error in selenium

前端 未结 3 1869
广开言路
广开言路 2020-12-07 06:07

Here is the HTML code, i\'m trying to select \'select customer\' drop-down.

相关标签:
3条回答
  • 2020-12-07 06:27
    WebElement selectMyElement = driver.findElement(this.getObject(By.Id("Id of Your DropDown"))); 
    selectMyElement.click();
    
    Actions keyDown = new Actions(driver);
    keyDown.sendKeys(Keys.chord(Keys.DOWN, Keys.DOWN)).perform();
    

    Above worked for me

    0 讨论(0)
  • 2020-12-07 06:28

    First check that:

    Drop down in your UI/FrontEnd is using "select" method or not ?

    And if not then use below snippet that will click in drop down and select value.

    WebElement selectMyElement = driver.findElement(this.getObject(By.Id("Id of Your DropDown"))); 
    selectMyElement.click();
    
    Actions keyDown = new Actions(driver);
    keyDown.sendKeys(Keys.chord(Keys.DOWN, Keys.DOWN)).perform();
    
    0 讨论(0)
  • 2020-12-07 06:36

    This exception generally occurs when we use Select command to select dropdowns which are not built by using "select" tag.

    You can try by using sendkeys to select dropdown, just give displayed text of option in sendkeys.

    If above does not work, then go for click on dropdown and again click on required option.

    If it is auto complete dropdown, then click on that dropdown input box and go for senkeys char by char with small sleep, so that required option will be displayed.

    0 讨论(0)
提交回复
热议问题