小编kus*_*hal的帖子

如何点击selenium中的自定义属性?

我有以下 html:它有一个类和一个自定义属性,我有几个具有相同 className 的标头。我想知道如何唯一地获取这个元素并单击它。

<h4 class="font-white topic-heading progress-header no-margin width-80 d-table-cell" data-collapse-id="1">I. Introduction</h4>
Run Code Online (Sandbox Code Playgroud)

这就是我尝试过的:-

我尝试使用 data-collapse-id="1" 获取 class="font-white..." 的属性:

var element = driver.findElement(By.xpath("//*[@class='font-white topic-heading progress-header no-margin width-80 d-table-cell']")).getAttribute('data-collapse-id="1"');
console.log(element); // this prints a promise.

element.click(); //element.click is not a function exception 
Run Code Online (Sandbox Code Playgroud)

我也尝试过:-

var element = driver.findElement(By.xpath("//*[@data-collapse-id='1']"));

element.click(); // element.click is not a function exception.
Run Code Online (Sandbox Code Playgroud)

我想知道如何在硒中获取这个元素并单击它。

这是整个 div:

<div class="page-width d-table topic-heading-div">
   <h4 class="font-white topic-heading progress-header no-margin width-80 d-table-cell" data-collapse-id="1">I. Introduction</h4>
   <i class="fa fa-check font-white font-18 width-20 d-table-cell text-center vertical-center" aria-hidden="true"></i> …
Run Code Online (Sandbox Code Playgroud)

javascript selenium xpath nodes

2
推荐指数
1
解决办法
8373
查看次数

标签 统计

javascript ×1

nodes ×1

selenium ×1

xpath ×1