开发者

selenium 2 - C# SelectElement not selecting in Chrome

开发者 https://www.devze.com 2023-03-17 00:27 出处:网络
I\'m using the following code in C# to select a value in a dropdown list: new SelectElement(driver.FindElement(By.Name(\"element\"))).SelectByIndex(2);

I'm using the following code in C# to select a value in a dropdown list:

new SelectElement(driver.FindElement(By.Name("element"))).SelectByIndex(2);

This works with Firefox and IE8 but not with Chrome, nothing gets selected. Are there any know issues with SelectElement? Any alternatives to get it to work in Chrom开发者_JS百科e?

I'm using the standalone server 2.0rc3 and Chrome 12


For anyone else having this problem, I solved it by clicking on the element and sending the keys to select the value, so something like:

driver.FindElement(By.Name("element")).Click();
driver.FindElement(By.Name("element")).SendKeys("some value");


This is a known issue with the Chrome driver. The IWebElement.Select() and .Toggle() methods were deprecated in 2.0RC3, requiring you to use .Click() instead. The SelectElement support class was updated to handle this change; however, the ChromeDriver.exe (which is built and provide by the Chromium team) has yet to catch up. So using IWebElement.Click() on an element doesn't yet work in Chrome.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号