简体   繁体   English

Javascript-在HTML页面上的类中获取特定DIV元素中的所有链接并创建数组

[英]Javascript - getting all links in specific DIV elements in a class on a HTML page and creating an array

I am trying to create an automation to perform some action to a HTML page. 我正在尝试创建一种自动化来对HTML页面执行一些操作。 This page contains a complex table wit a lot of divs inside divs. 此页面包含一个复杂的表,其中包含许多div内的div。 Every line of this page is clickable and will open another page. 该页面的每一行都是可单击的,将打开另一个页面。 I have already created the automation that will perform tasks on this page that opens, but I need to automate clicking on every line on this first table first. 我已经创建了将在打开的页面上执行任务的自动化程序,但是我需要首先自动单击第一张表中的每一行。

Analyzing the first column of this page, I have this Xpath for the first 3 cells of the first colum: 分析此页的第一列,对于第一个列的前三个单元格,我具有以下Xpath:

/HTML[1]/BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/TABLE[1]/TBODY[1]/TR[3]/TD[1]/TABLE[1]/TBODY[1]/TR[2]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/DIV[1]/DIV[2]/DIV[2]/SPAN[1]/UL[1]/LI[3]/DIV[1]/DIV[2]


/HTML[1]/BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/TABLE[1]/TBODY[1]/TR[3]/TD[1]/TABLE[1]/TBODY[1]/TR[2]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/DIV[1]/DIV[2]/DIV[2]/SPAN[1]/UL[1]/LI[4]/DIV[1]/DIV[2]


/HTML[1]/BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/TABLE[1]/TBODY[1]/TR[3]/TD[1]/TABLE[1]/TBODY[1]/TR[2]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/DIV[1]/DIV[2]/DIV[2]/SPAN[1]/UL[1]/LI[5]/DIV[1]/DIV[2]

and this for the last cell of the first column: 这是第一列的最后一个单元格:

/HTML[1]/BODY[1]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/TABLE[1]/TBODY[1]/TR[3]/TD[1]/TABLE[1]/TBODY[1]/TR[2]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[2]/TABLE[1]/TBODY[1]/TR[1]/TD[1]/DIV[1]/DIV[2]/DIV[2]/SPAN[1]/UL[1]/LI[102]/DIV[1]/DIV[2]

You can see that there's just one element varying from 3 to 102. 您会看到只有一个元素在3到102之间变化。

All cells in the first column have this HTML 第一列中的所有单元格都具有此HTML

<div style="float:left;" class="ajaxListColumn ajaxListColumnInternal ajaxListColumn_2 ajaxListSearchable ajaxListRowDivActionable ajaxListRowDivColumnActionItem default-to-first-column">
<span class="left">Item 1</span>
&nbsp;
</div>

what varies from cell to cell on the first column is this Item 1, 2, 3, etc... 第1、2、3等项在第一列的每个单元格之间是不同的...

What I need is, to create an array of elements, so I can click them with Javascript and then perform the automation I already have on each page that will open for each click on a line of this table. 我需要的是创建一个元素数组,因此我可以使用Javascript单击它们,然后执行该页面上每单击一次将打开的每个页面上已经具有的自动化功能。 How do I get this array? 我如何获得这个数组? Thanks. 谢谢。

I am not sure what other informations you guys need to answer this. 我不确定你们需要什么其他信息来回答这个问题。 Please ask me and I will post here. 请问我,我会在这里发布。

If you just want an XPath which will select all those rows, just take your second example and remove the "[102]". 如果只需要一个XPath来选择所有这些行,请以第二个示例为例,并删除“ [102]”。

                                                Here: ↓
/HTML[1]/BODY[1]...blah blah.../DIV[2]/SPAN[1]/UL[1]/LI/DIV[1]/DIV[2]

This will select all those LI elements. 这将选择所有那些LI元素。

I will update this answer if I've got the wrong end of the stick. 如果杆的末端有错误,我将更新此答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM