出于某种原因,当我没有奔跑时,我能够登录http://www.neighborhoodscout.com。但是,当我运行无头PhantomJS时,我无法登录,并且无法找到成功登录后返回的元素。
Phantom JS版本1.9.8
driver = webdriver.PhantomJS() driver.set_window_size(1124, 850) driver.get(url) time.sleep(2) driver.find_element_by_id("login").click() time.sleep(2) driver.find_element_by_id("user_email").send_keys(username) driver.find_element_by_id("user_password").send_keys(password) time.sleep(4) driver.find_element_by_id("login-button").click()
为什么它适用于非无头之人而不适用于phantomjs?
没有回溯错误,只是由于某种原因无法登录?
我正在通过以下方式寻找特定元素:
ele_found=EC.presence_of_element_located(driver.find_element_by_id('flash_notice')) is not None
下面的代码对我来说很好!
import time from selenium import webdriver from selenium.webdriver.common.keys import Keys url = 'http://www.neighborhoodscout.com/' username = 'abc@bcas.fulba.com'#change here password = '12345'#change here driver = webdriver.PhantomJS(r"C:\phantomjs.exe") driver.set_window_size(1124, 850) driver.get(url) time.sleep(2) login = driver.find_element_by_xpath("//a[@ id='login']") login.click() time.sleep(5) usr = driver.find_element_by_xpath("//input [@id='user_email' and @class='input-text']") passw = driver.find_element_by_xpath("//input [@id='user_password' and @class='input-text' ]") logbtn = driver.find_element_by_xpath("//input [@id='login-button' and @class='btn']") usr.send_keys(username) passw.send_keys(password) logbtn.click() time.sleep(4) if '/users/sign_out' in driver.page_source: print "Logged In" driver.close()