Im writing a python script using selenium webdriver to get some data from a website, and Im trying to click the next button in this webpage. Where the button is defined:
<a id="ctl00_FullRegion_npsGridView_lnkNext" class="nextCol" href="javascript:__doPostBack('ctl00$FullRegion$npsGridView$lnkNext','')">Next</a>
Wih the following code in python
URL='http://www.nordpoolspot.com/Market-data1/Elspot/Area-Prices/ALL1/Hourly/'
nextId="ctl00_FullRegion_npsGridView_lnkNext"
browser=webdriver.PhantomJS('./phantomjs')
browser.get(URL)
nextBtn=browser.find_element_by_id(nextId)
time.sleep(5)
nextBtn.click()
This works well when using Firefox or chrome Webdriver but with Phantomjs I get the following error.
selenium.common.exceptions.WebDriverException: Message: u'Error Message => \'Click
failed: ReferenceError: Can\'t find variable: __doPostBack\'\n caused by Request
This error comes up in alot of google searches but havnt really found a way fix it when using phantomjs.
Try sending a different User-Agent header:
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
user_agent = (
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36"
)
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent
browser = webdriver.PhantomJS(desired_capabilities=dcap)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With