简体   繁体   English

如何使用 Selenium WebDriver 读取 ::after 单选按钮元素的属性

[英]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.

相关问题 如何使用 selenium webdriver 在 JQGrid 中选择单选按钮 - How to select Radio button in JQGrid using selenium webdriver 如何使用带有Java的Selenium WebDriver选择单选按钮? - How to select radio button using Selenium WebDriver with Java? 如何通过不使用x路径来选择Selenium Webdriver中的单选按钮 - how to select radio button in selenium webdriver by not using x path 如何使用Selenium Webdriver选择具有多个CSS属性的元素 - How to select an element with multiple CSS attributes using Selenium Webdriver 如何使用Selenium WebDriver检查单选按钮? - How to check a radio button with Selenium WebDriver? 如何检查单选按钮是否在 Selenium WebDriver 中被选中? - How to check if the radio button is selected or not in Selenium WebDriver? 如何在Selenium Webdriver中选择单选按钮? 动态选择单选按钮 - How to select radio button in selenium webdriver ? dynamic select of radio button 如何使用 Selenium 和 Java 识别是否选择了带有伪元素::after 样式的单选按钮选项 - How to identify if a radio button option styled with pseudo element ::after is selected or not using Selenium and Java 在Java中使用Selenium WebDriver确定单选按钮值 - Determining Radio Button Value Using Selenium WebDriver in Java 在<label>使用Selenium WebDriver</label>的列表中找到选定的单选按钮 - Find the selected radio button in a list of <label> using selenium webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM