[英]How to click on a link which contains a variable into “href” attribute?
I am writing acceptance tests using Selenium + WebdriverIO. 我正在使用Selenium + WebdriverIO编写验收测试。 And I have some problems with that - I can't click on this link
我有一些问题 - 我无法点击此链接
client.click('a[href=#admin/'+ transactionId + ']')
transactionId - it is a variable which contains ID of transaction. transactionId - 它是一个包含事务ID的变量。 My HTML code:
我的HTML代码:
<div class="ui-data-table">
<thead>...</thead>
<tbody>
<tr><td class="tac">
<span class="tooltip" title="Transaction"><i class="icon-transaction"></i></span>
</td>
<td class="tac no-break">Today 10:23</td>
<td class="break-all"></td>
<td class="tac">
N/A
</td>
<td>Artem</td>
<td class="tac">
<span class="tooltip" title="Pending">
<i class="icon-clock"></i>
</span>
</td>
<td class="break-all">Artem Arsenowitch</td>
<td class="tac">
<a href="#admin/aceb3f65-4078-4f47-8850-95ac9135fad3"><i class="icon-arrow-circle-right"></i></a>
</td></tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
<tr>...</tr>
</tbody>
</div>
Every "tr" tag has the same structure as you can see above and "a" tag with appropriate id inside href attribute. 每个“tr”标签都具有与您在上面看到的相同的结构,以及在href属性中具有适当id的“a”标签。 The main problem consist in this code:
主要问题在于此代码:
('a[href=#admin/'+ transactionId + ']')
because it returns 因为它返回
(a[href=#admin/undefined])
Girish Sortur Thanks for you answers, but I found only one solution using this code: Girish Sortur感谢您的回答,但我发现只有一个使用此代码的解决方案:
.getAttribute("p.tac", "transaction-id")
.then(function(attr){
transactionId = attr;
transactionURL = 'a[href="#admin/'+ transactionId + '"]';
})
.click('a[href="#admin"]')
.waitForExist("div.ui-data-table", 10000).then(function(){
client.click(transactionURL)//That is working now
})
Using only Selenium, you should find the element first and then click it because click()
method doesn't take an argument. 仅使用Selenium,您应首先找到该元素,然后单击它,因为
click()
方法不接受参数。 Here's how you can do it - 这是你如何做到的 -
driver.findElement(by.xpath('a[href="#admin/'+ transactionId + '"]')).click();
However if you are using webdriver-io along with selenium then make sure your transactionId is getting generated first and then click it as async javascript executes quickly without waiting for transaction-id to return. 但是,如果您使用webdriver-io和selenium,请确保首先生成您的transactionId,然后单击它,因为异步javascript快速执行而无需等待transaction-id返回。 Here's how -
这是如何做 -
.waitForExist("p.tac", 10000)
.getAttribute("p.tac", "transaction-id")
.then(function(attr){
transactionId = attr;
})
.click('a[href="#admin"]').waitForExist("div.ui-data-table", 10000)
.waitForVisible('a[href="#admin/'+ transactionId + '"]', 10000)
.click('a[href="#admin/'+ transactionId + '"]');
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.