How to click a “select option” and then evaluate loaded content with casperjs

后端 未结 9 1496
长情又很酷
长情又很酷 2021-01-02 01:46

I\'m trying to crawl the sizes for this product:

Link to product

The problem: The sizes are loaded after the color of the product is selected.

In th

9条回答
  •  天命终不由人
    2021-01-02 01:59

    tejesh95's solution worked for me with a few minor changes, #1 I couldn't get findElementById to work so switched it to 'document.querySelector('#selectorId)' . I also had to change 'onchange' to 'onclick'. Here's the code within the casperjs test harness:

    casper.then(function() {
      this.evaluate(function() {
      var select_element = document.querySelector('#selectorId')
      select_element.value = 'stringValue'
      select_element.onclick
    })
    

    })

    Follow on note: Your mileage may vary on the above, I found inconsistent results elsewhere, the text value would update, but the underlying control wouldn't fire. Frustrating!

提交回复
热议问题