[英]How to read ::after attributes of a radio button element using Selenium WebDriver
I have been trying to read the content inside an html tag which has features like ::before and ::after using selenium webdriver (Java), but I'm having hard time to read those contents since they are dynamic.我一直在尝试使用 selenium webdriver (Java) 读取具有 ::before 和 ::after 等功能的 html 标签内的内容,但由于它们是动态的,因此我很难阅读这些内容。
For example, In the below HTML code,例如,在下面的 HTML 代码中,
<label class="radio radio-label-horizontal control-label" for="id_Fruit_1">
<input value="Banana" name="Fruit" id="id_Fruit_1" data-field-name="Choices" data-field-type="Structured" tabindex="2" type="radio">
<span class="radio-label">
::before
Banana
::after
</span>
</label>
That's a code snippet for a radio button which is selected, but when I switch the radio button to another choice, it simply removed ::after from the "span" element, and it did not make any change to the "input" element.这是一个被选中的单选按钮的代码片段,但是当我将单选按钮切换到另一个选项时,它只是从“span”元素中删除了 ::after ,并且没有对“input”元素进行任何更改。
But when I did the below java selenium code, I only see 'Banana', and I was expecting to get '::before Banana ::after'但是当我执行下面的 java selenium 代码时,我只看到了 'Banana',我期待得到 '::before Banana ::after'
driver.findElement(By.cssSelector(".radio-label")).getText();
Can you please explain how I can find out whether my radio button is checked or not using selenium?你能解释一下我如何知道我的单选按钮是否使用硒被选中?
You can isSelected() method to figure out whether radio button is selected or not.您可以使用 isSelected() 方法来确定单选按钮是否被选中。
List radioBtn = driver.findElements();列表 radioBtn = driver.findElements(); boolean selected=false;布尔选择=假; selected=radioBtn.get(0).isSelected() will return true/false whether the button is selected or not. selected=radioBtn.get(0).isSelected() 无论按钮是否被选中,都将返回真/假。 if(selected) //perform actions if(selected) //执行动作
您只能将文本传递到您的应用程序中,而不是像以下和祖先这样的 HTML 标签
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.