问题
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