[英]How to verify whether a tag is present in the html code for a drop down using java in Selenium Webdriver
I have a disabled drop down with Values auto populated as True or False. 我有一个禁用的下拉列表,其中“值”自动填充为True或False。 For the auto populated value, I can see a tag named "selected" when I do the inspect element.How can I verify whether the tag "Selected" is present for the drop down?
对于自动填充的值,执行检查元素时可以看到名为“ selected”的标签。如何验证下拉列表中是否存在“ Selected”标签?
below is the HTML part 以下是HTML部分
<select name="text" class="Product_Selected" disabled>
<Option value="Flag_True" selected>TRUE </option>
<Option value="Flag_False">False </option> ==$0
</select>
As you can see above, I have selected my previous input as TRUE, so next time im getting the drop down auto populated with TRUE and is DISABLED. 正如您在上面看到的那样,我将之前的输入选择为TRUE,因此下次我将使用TRUE自动填充下拉列表并且将其禁用。 Is there any way where I can see whether tag "selected" is present for that disabled drop down using JAVA code for Selenium Webdriver
有什么办法可以使用针对Selenium Webdriver的JAVA代码查看该禁用下拉列表是否存在标签“ selected”
OR Can I get the auto populated value of the Disabled Dropdown? 或能否获得“禁用的下拉菜单”的自动填充值?
You don't have to do anything complicated... just treat it like any other SELECT
element. 您不必做任何复杂的事情……就像对待其他任何
SELECT
元素一样。 There is a special class in Selenium designed to make it easier to interact with SELECT
elements called... Select
. Selenium中有一个特殊的类,旨在使与
SELECT
元素(... Select
交互更加容易。 I just tested this code with true and false selected and it works just fine even though the element is disabled. 我只是在选择了true和false的情况下测试了此代码,即使禁用了该元素,它也可以正常工作。
Select e = new Select(driver.findElement(By.cssSelector("select.Product_Selected")));
System.out.println(e.getFirstSelectedOption().getText());
You get your SELECT
element and send it to the Select
constructor. 您将获得
SELECT
元素,并将其发送到Select
构造函数。 Then you can interact with the Select
element with all the new functionality. 然后,您可以与具有所有新功能的
Select
元素进行交互。 The example above just gets the selected option (first selected option in the case of a multi-select, but that doesn't apply here) and returns the text displayed, eg TRUE. 上面的示例仅获取选定的选项(如果是多选,则是第一个选定的选项,但不适用于此处),并返回显示的文本,例如TRUE。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.