从网站

时间:2016-01-21 17:58:13

标签: python selenium

我有测试页面:

<input type='button' id='button' onclick="alert('foo');" value='My Button' />

我想在点击按钮时获取提醒文本,然后使用

from selenium import webdriver
from selenium.webdriver.common import alert

phantom = webdriver.PhantomJS()
phantom.get('/home/macabeus/ApenasMeu/test.html')
phantom.find_element_by_id('button').click()
x = alert.Alert(phantom)
print(x.text)

但是,在最后一行,我得到了错误:

ValueError: Expecting value: line 1 column 1 (char 0)

为什么呢?如何解决?

1 个答案:

答案 0 :(得分:3)

GhostDriver(PhantomJS的webdriver)问题跟踪器存在未解决的问题:

这是一个有效的解决方法(打印{!! nl2br($documentData) !!}):

foo