driver = webdriver.PhantomJS()
driver.get('http://open.qq.com/login?from=http%3A%2F%2Fop.open.qq.com%2F')
driver.implicitly_wait(30)
driver.switch_to.frame('login_frame')
driver.find_element_by_id('u').send_keys('157447865')
driver.find_element_by_id('p').send_keys('abc_123_')
driver.find_element_by_id('login_button').click()
time.sleep(5)
driver.find_elements_by_class_name('btn-manage')[1].click()
time.sleep(5)
app_num = driver.find_element_by_tag_name('tbody').text
driver.quit()
if app_num:
day_total = app_num.split('\n')[0].split()
return day_total[-3].replace(',', ''), day_total[-2].replace(',', '')
return '', '0'
当我执行代码' driver.find_elements_by_class_name(' btn-manage')[1]'时,驱动程序无法标记class_name是' btn的名称-manage',实际上有两个元素。为什么在driver.find_elements_by_class_name(' btn-manage')中通过driver.find_elements_by_class_name(' btn-manage')查找元素,但是Firefox可以。
答案 0 :(得分:1)
这是捕获。
driver.find_element_by_id('login_button').click()
#are you sure you have logged in successfully under PhantomJS?
time.sleep(5)
driver.find_elements_by_class_name('btn-manage')[1].click()