[英]How to empty the select element or to select empty option? c# webdriver
I need select element to be empty, how can I do that? 我需要选择元素为空,我该怎么办? I tried with selectbytext and empty value, but it did not worked. 我尝试使用selectbytext和空值,但是没有用。
selectElement2.SelectByText(""); //(failed)
<option value=""></option>
<option value="1" selected="selected">Testing1</option>
<option value="2">Testing2</option>
...
You can try 你可以试试
new Select(driver.findElement(By.xpath("//selection box"))).selectByIndex(0);
//or
new Select(driver.findElement(By.xpath("//selection box"))).selectByValue("");
//or
driver.findElement(By.xpath("//selection box")).sendKeys("");
此语法可能会有所帮助
$('#DdlSiteName').empty();
You can use Deselect
method from Select class 您可以从Select类使用Deselect
方法
selectElement2.DeselectByValue("1");
// or
selectElement2.DeselectByIndex(1);
// or
selectElement2.DeselectByText("Testing1");
In the case you presented, it should just be 在您提出的情况下,应该只是
selectElement2.SelectByValue("");
Take a look at the docs for .Net 看看.Net的文档
SelectByIndex()
, SelectByText()
, and SelectByValue()
are available. SelectByIndex()
, SelectByText()
和SelectByValue()
可用。 Index is by the index of the OPTION
tags, starting with 0, so index = 1 is "Testing1". 索引是从OPTION
标记的索引开始的,从0开始,因此索引= 1为“ Testing1”。 NOTE: Don't confuse index with value, in this case they are the same. 注意:不要将索引与值混淆,在这种情况下它们是相同的。 Text is the visible text in the dropdown, eg "Testing1" in your sample is currently selected. 文本是下拉菜单中的可见文本,例如,当前已选择样本中的“ Testing1”。 Value is the value
inside the OPTION
tag, eg "1" for "Testing1". 值是OPTION
标记内的value
,例如,“ Testing1”的value
“ 1”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.