css - 有两个同名的类。如何在 Webdriver.IO 中使用 css/xpath 选择其中一个元素?

标签 css selenium-webdriver xpath webdriver webdriver-io

我使用 Webdriver.io 并想要选择“text-fields-container”类中的一个元素(它是一个密码字段)。两个类具有相同的名称。如何选择具有 type="password"的第二类。

<form>
	<div class="text-fields-container">
		<div>
			<input type="text" class="text-field" placeholder="Email" required stype="margin-bottom: 1.125rem;">
		</div>
		<div>
			<input type="password" class="text-field" placeholder="Password" required stype="margin-bottom: 5px;">
		</div>
	</div>
</form>

最佳答案

要选择具有type="password"的第二个类别,您可以使用以下任一定位器策略:

  • css选择器:

    "input.text-field[type='password']"
    
  • cssSelector(粒度):

    "input.text-field[type='password'][placeholder='Password']"
    
  • xpath

    "//input[@class='text-field' and @type='password']"
    
  • xpath(粒度):

    "//input[@class='text-field' and @type='password' and @placeholder='Password']"
    

关于css - 有两个同名的类。如何在 Webdriver.IO 中使用 css/xpath 选择其中一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49602832/

相关文章:

python - 如何通过多个文本字符串查找元素?

html - 将垂直类别菜单变成手机上的下拉菜单

html - 适应屏幕的 div 高度

javascript - 根据列值更改表格行的颜色

html - css根据背景高度自动调整div高度

java - Selenium 等待 Element 的任何一个可见

python - Selenium/python - 找不到部分链接文本

html - 使用 XSL 导入 HTML 表格

class - XPath通过类名选择图像

html - 有没有办法检测 xslt 中的数字字符串?