单击TruClient中文本旁边的链接 [英] Click on a link beside text in TruClient

查看:55
本文介绍了单击TruClient中文本旁边的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个页面,其中包含数十行,列出了我们创建的案例.我们为案例指定了唯一的案例,因此我们可以在TruClient中使用循环来向下滚动页面,直到找到该文本为止.然后,我们在页面上单击该文本左侧的链接.在HTTP协议中,这非常简单,因为我们可以使用regex轻松拔出链接,但是使用TruClient,我们看不到它.

We have a page where with dozens of rows listing cases that we have created. We have named the cases unique so we can use a loop in TruClient to scroll down the page until we find that text. Our page has us then clicking on the link to the left of that text. It's very straight forward in the HTTP protocol as we can use regex to easily pull out the link but with TruClient we can't see that.

最新链接并不总是显示在屏幕的顶部或底部,在进入此页面之前,我们无法获取链接的详细信息(功能是我们创建此案例的原因,而案例ID不会显示给之前的页面)

The latest link is not always at the top or bottom of the screen, and we can't grab the link details before we get to this page (functionality has us creating this case, and the case ID isn't presented to the page before this)

我能看到的最接近的功能是使用单击链接",并使用相关对象"并将其指向我们要标识的文本,但是没有一种方法可以对要我们想用作锚点.

The closest functionality that I can see would be use a Click on link took, and use the "Related Object" and point it to the text that we want to identify, but there isn't a way to parameterise the text that we want to use as the anchor.

因此在下面的示例中,我创建的最新案例是Name20200323005,我想单击它右侧的链接.

So in the example below the latest case that I created was Name20200323005 and I want to click on the Link to the right of it.

以前有没有人做过这样的事情,或者建议我们可以研究的事情?

Has anyone done anything like this before, or suggest anything we could research?

推荐答案

首先,我想确保我清楚地了解您的要求.任务是让TruClient根据搜索Name ###########的值来单击链接.是吗?

First I want to make sure I understand your request clearly. The task is let TruClient click the link based on search the value of Name###########. Is it right?

TruClient支持几种识别测试对象的方法:

TruClient support several ways to identify the test object:

  1. 自动
  2. 描述符
  3. JavaScript
  4. XPath

我认为自动或描述符不适合此请求.我们需要编写一些JS代码来完成请求.

I don't think the automatic or descriptor are fit for this request. We need to write some JS code complete the request.

  1. 从步骤">对象">"ID方法"将对象标识方法更改为js.
  2. 单击输入框右侧的编辑图标.确保JS代码的评估值引用了正确的DOM对象.这是基于您的示例的示例代码,用于过滤Link元素:

添加的引用firstChild就像您提到的那样,该链接包含在div元素中.很高兴知道它有效.:)

Added reference firstChild as you mentioned the link is contained in a div element. Glad to know it works. :)

Array.prototype.slice.call(document.querySelectorAll('td'), 0).filter(td=>td.innerText=="Name20200323005")[0].previousElementSibling .previousElementSibling.firstChild 

这篇关于单击TruClient中文本旁边的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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