webdriver C# - 下拉selectByVisibleText [英] webdriver C# - dropdown selectByVisibleText
问题描述
试图在下拉菜单中选择一个词.
Trying to select a word inside a dropdown menu.
在 Webdriver IDE 中,点击下拉菜单(Id 为p",点击下拉菜单中的Barcelona"一词.:
In Webdriver IDE appear this to click the dropdown (which Id is "p" and the to click the word "Barcelona" inside the dropdown.:
我只能使用以下方法打开下拉菜单:
I just can open the dropdown menu using:
driver.FindElement(By.Id("p")).Click();
现在我试图在这个下拉菜单中选择一个词,使用selectelement"和select visibleText",但在 C# Webdriver 中对我不起作用.
Now I'm trying to select a word inside this dropdown menu, using "selectelement" and "select visibleText" but does not work in C# Webdriver for me.
SelectElement selector = new SelectElement.selectByVisibleText("Barcelona");
有什么帮助吗?
使用 C# Webdriver 而不是 java.
Using C# Webdriver and not java.
推荐答案
我认为问题出在 SelectElement 初始化上.你可以试试下面的代码:
I think the problem is in the SelectElement initialization. You can try the following code:
SelectElement selectElement = new SelectElement(driver.FindElement(By.Id("p")));
selectElement.SelectByText("Germany");
如果您是 C# WebDriver API 的新手,您会发现以下文章很有用:http://automatetheplanet.com/getting-started-webdriver-c-10-minutes/
If you are new in the C# WebDriver API, you can find the following article useful: http://automatetheplanet.com/getting-started-webdriver-c-10-minutes/
这篇关于webdriver C# - 下拉selectByVisibleText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!