【问题标题】:CasperJS won't click on table of datesCasperJS 不会点击日期表
【发布时间】:2016-01-02 03:53:47
【问题描述】:
<td>
    Search Downloadable Full Charts by Date:
    <br>
    <select name="raceDate">
        <option value="20150821">August 21</option>
        <option value'"20150822">August 22</option>
        ...these options continue until yesterday(the default)
        ...
        <option selected="" value="20151004">October 4</option>
    </select>
    <input type="submit" onclick="setSearch('D');" value="Search">

使用 RSelenium 可以:

webElem <- remDr$findElement(using = 'xpath',
                             "/html/body/div/div[4]/div[1]/center/
                             table/tbody/tr/td/form/table/tbody/tr/td/input")
webElem$clickElement()

但是使用 casperjs 我会收到 xpath 不存在的错误消息,即使我使用 css 选择器:

casper.then(function(){
    this.clickLabel('.interior-content.col-sm-8>center>table>tbody>tr>td>form>table>tbody>tr>td>input');
});
casper.then(function(){ 
    console.log('clicked search default search ok, new location is ' + this.getCurrentUrl());
}); 
dave@dbox:~$ casperjs --version 1.1.0-beta3 dave@dbox:~$ phantomjs --version 1.9.2

Linux dbox 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u4 (2015-09-19) x86_64 GNU/Linux

我还尝试了堆栈以及 CasperJS 文档中的许多其他示例。

【问题讨论】:

  • 按日期搜索可下载的完整图表:

标签: javascript css-selectors click casperjs


【解决方案1】:

.interior-content.col-sm-8&gt;center&gt;table&gt;tbody&gt;tr&gt;td&gt;form&gt;table&gt;tbody&gt;tr&gt;td&gt;input 是 CSS 选择器,而不是标签(元素文本)。您需要使用casper.click(selector) 而不是casper.clickLabel(text)

this.click(".interior-content.col-sm-8>center>table>tbody>tr>td>form>table>tbody>tr>td>input");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多