2
我有測試頁:從警報獲取文本在網站
<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)
爲什麼?如何解決它?
我得到相同的錯誤,並且'alert'不可調用 – Macabeus
@Macabeus是的,好點。讓我試着重現這個問題。順便說一句,Firefox中會發生什麼? – alecxe
我還沒有用Firefox進行過測試,因爲我需要使用PhantomJS。這是更快,需要更少的內存 – Macabeus