ERROR: Caught exception [ERROR: Unsupported command [addSelection |]

核能气质少年 提交于 2019-12-11 01:24:42

问题


I am using selenium web driver with C# and on trying to select an item on the available list I am receiving an error as:

ERROR: Caught exception [ERROR: Unsupported command [addSelection |

Can someone help me with this? Any workaround?

What I am trying is to select an item from a list which is on the left side and then click on the button (>) to move it to the right side.


回答1:


You are getting the error because not everything in the IDE can be converted into the WebDriver API's.

You have to think about this logically, and not rely on the IDE to start generating this code for you.

The C# bindings have a SelectElement class, inside OpenQA.Selenium.Support namespace, you'll need to add a reference to the WebDriver.Support.dll assembly.

It encompasses 'common' use cases for select elements. With this, you can probably mimic the behaviour of addSelection. I haven't used the IDE so am not sure what that command is intended to do, but you can simply do something like:

IWebElement element = driver.FindElement(By.Id("a"));
SelectElement select = new SelectElement(element);
select.SelectByValue("2");
select.SelectByText("George");
select.SelectByIndex(1);



回答2:


Select selectbox= new Select(driver.findElement(By.id("MY ID"))); selectbox.selectByIndex(2);



来源:https://stackoverflow.com/questions/16097534/error-caught-exception-error-unsupported-command-addselection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!