为什么代码适用于webdriver.Firefox但不能与webdriver.PhantomJS一起使用?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.PhantomJS() # why not?
# driver.set_window_size(1400, 1050)
# driver = webdriver.Firefox() # Firefox 45, works correctly
driver.get("https://www.rec-registry.gov.au/rec-registry/app/public/lgc-register")
driver.find_elements_by_tag_name('button')[4].click() # status
# show the needed elements for the next action,
# enter(open the door) to the div.ms-drop area
driver.find_elements_by_class_name('ms-drop')[4].find_element_by_css_selector('ul>li:nth-child(12)').click() # registered
driver.find_element_by_id('search-submit').send_keys(Keys.RETURN) # search
driver.save_screenshot('lgc1.png')
答案 0 :(得分:1)
您应该尝试使用.click()
进行点击,而不是send_keys(Keys.RETURN)
,如下所示:
driver.find_element_by_id('search-submit').click()