How to select an option with CasperJS
问题 I try to set select option attribute to selected. But I try to avoid using nth-child in CasperJS because there are bugs in PhantomJS's nth-child. So I try to use this as the subtitution of jQuery(css_path). function setSelectedCountry(i){ window.__utils__.echo("i :"+i); var query = "//*[@id='cboCountry']/optgroup[2]/option["+i+"]"; __utils__.getElementByXPath(query).setAttribute("selected","selected"); } But, when I evaluate that code by this way this.evaluate(setSelectedCountry, 5); The