Internet Explorer单击表的特定行的图标和按钮 [英] Internet Explorer click an icon and a button of a specific line of a table

查看:120
本文介绍了Internet Explorer单击表的特定行的图标和按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两天前我问过一个类似的问题,但我知道再次遇到类似问题,但又有所不同. 上一个问题问有关问题

I've asked a similar question two days ago but I know stumble again on a similar problem but somehow different. previous question asked on a related problem

我有许多具有相同结构的行的报告.我需要单击第n行上的图标.该报告以单元格的形式组织,因此我知道我的图标在该报告的第一位置(列).单击该图标后,我还必须单击第十列中的一个按钮.

I have a report of many lines with the same structure. I need to click an icon that is on the nth line. That report is structured in cells so I know that my icon is in the first position (column) of that report. After I have click that icon I'll also have to click on a button in the 10th column.

我已经知道如何使用该代码访问有问题的页面

I already know how to access the page in question with that code

Sub click_button_no_hlink()


Dim i As Long
Dim IE As Object
Dim Doc As Object
Dim objElement As Object
Dim objCollection As Object

Set IE = CreateObject("InternetExplorer.Application")               'create IE instance

IE.Visible = True

IE.Navigate "https://apex.xyz.qc.ca/apex/prd1/f?p=135:LOGIN_DESKTOP::::::"  ' Adress of web page

While IE.Busy: DoEvents: Wend             'loading page

这第一部分很容易不是吗?而且我知道如何处理.之后,我尝试对此进行不同的更改,但是它什么都不做,或者我收到一条错误消息.显然,我不完全了解我正在使用"querySelector"这个东西……

This first part is easy isn't? And I know how to handle it. Afterward I tried different variation around this but it either do nothing, or I get an error message. Obviously I don't fully understand what I'm doing with the "querySelector" thing…

dim step_target as string
step_target = 2

'identify all the lines of my table containing lines, containing icons 
'and button to click on
Set objCollection = IE.document.getElementsByClassName("highlight-row")       
i = 0
Do While i < objCollection.Length
'cell 2 is the one containing the step I'm targetting
    If objCollection.Item(i).Cells(2).innerText = step_target  Then                  
    'that's not doing anything    
   objCollection.Item(i).Cells(9).Click
   'tried many syntax around this with no luck
    IE.document.querySelector([objCollection.Item(i).Cells(9)]).FireEvent ("onclick")       
    End If
    i = i + 1
Loop

以下是页面代码的图像

显示报告的所有行

显示特定行的所有代码行

Showing all code lines of a particular line

,现在是我需要单击的第一个图标的代码(这是我需要帮助的地方;-)如何调用该动作)

and now the code of that first icon I need to click on (this is where I need help ;-) how can I call that action)

最后,我还需要单击该按钮的代码

and finally the code of that button I also need to click on

再次,谢谢大家,感谢您抽出宝贵的时间来帮助我解决这个问题.

Again, I thank you all in advance, for the time you'll take to help me along this.

推荐答案

您可以首先将属性选择器与后代组合器和a类型选择器组合使用

you could try attribute selector for first in combination with descendant combinator and a type selector

ie.document.querySelector("[headers='ID_DET_DEM_TRAV_STD'] a").click

您可以尝试将属性选择器与后代组合器和input类型选择器结合使用

you could try attribute selector for second in combination with descendant combinator and input type selector

ie.document.querySelector("[headers='BOUTON1'] input").click

第二种替代方法是

ie.document.querySelector("[value=Fait]").click

通常,如果要按位置进行选择,例如您将使用的第1列和第10列

Typically, if you want to select by position e.g. 1 and 10th columns you would use

td:nth-of-type(1)
td:nth-of-type(10)

尽管您也可以使用tr:nth-of-type(n)来获得正确的行,例如第一排,第一列.然后添加例如您可能需要的任何子类型选择器.

Though you would also use a tr:nth-of-type(n) to get the right row as well e.g. first row, first col. Then add in any child type selector, for example, that you might need.

ie.document.querySelector("tr:nth-of-type(1) td:nth-of-type(1)")

子级a标记:

ie.document.querySelector("tr:nth-of-type(1) td:nth-of-type(1) a")

儿童input标签:将为:

IE.document.querySelector("tr:nth-of-type(4) td:nth-of-type(10) input").Click

这篇关于Internet Explorer单击表的特定行的图标和按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆