如何使用CasperJS点击超链接?

时间:2014-01-16 06:47:46

标签: dom casperjs

<div class="company-list-title"> … </div>
<ul id="company-list1" class="company-list">
    <li class="company-list-item"> … </li>
    <li class="company-list-item"> … </li>
    <li class="company-list-item"> … </li>
    <li class="company-list-item">
        <a class="company_link" href="javascript: applyswitch('1006084861', '1006084864')">

            E2E C2 Harmony US Plus_US_QBP-T39_1_201309161379373407264 (cluster 2: company 1006084861)

        </a>

如何使用CasperJS点击带有文字“E2E C2 Harmony US Plus_US_QBP-T39_1_201309161379373407264(第2组:公司1006084861)”的超链接?

以下代码不起作用:

casper.then(function() {  
this.test.assertExists({  
            type: 'xpath',  
            path: '//ul[@class="company-list"]'  
    }, "Got Here 1");  
    this.test.assertExists({   
            type: 'xpath',  
            path: '//ul[@class="company-list"]//a[text()="E2E C2 Harmony US Plus_US_QBP-  T39_1_201309161379373407264 (cluster 2: company 1006084861)"]'  
    }, "Got Here 2");  
    this.click(('//ul[@class="company-list"]//a[text()="E2E C2 Harmony US Plus_US_QBP-  T39_1_201309161379373407264 (cluster 2: company 1006084861)"]'), function() {  
    console.log("Woop!");  
});  
});  

1 个答案:

答案 0 :(得分:1)

您可以尝试使用clickLabel()

this.clickLabel('E2E C2 Harmony US Plus_US_QBP-T39_1_201309161379373407264 (cluster 2: company 1006084861)', 'a');