因此我正试图浏览NewEgg网站的不同部分。我又陷入了困境。如果您访问this link,则一旦加载页面,您就可以在右侧Shoprunner free 2-day shipping
看到。屏幕附有
当我选择Firefox
作为驱动程序时,它可以正常工作,但当我选择PhantomJS
时,它不会在ShopRunner下发送sign in
文本而不是生成以下页面:
如您所见,现在 SHOPRUNNER 徽标以及此处的文字。
我从Selinium得到以下错误:
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u'{"errorMessage":"Unable to find element with link text \'sign in\'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"95","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:52827","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\\"using\\": \\"link text\\", \\"sessionId\\": \\"f8ac9fc0-6b17-11e4-81d1-212ddc897fa8\\", \\"value\\": \\"sign in\\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/f8ac9fc0-6b17-11e4-81d1-212ddc897fa8/element"}}' ; Screenshot: available via screen
以下代码:
from selenium import webdriver
driver.get('http://www.newegg.com/Product/Product.aspx?Item=N82E16826104328&RandomID=8406339484211620141105131308')
sleep(120)#this does not make any difference either.
driver.save_screenshot('screen_aftersignin.png')
driver.find_element_by_link_text('sign in').click()