我有一个问题,我在python上使用selenium制作测试程序 步骤
我不理解两个相同的元素(#query),为什么第二个只是错误。 拜托,给我。
步骤4,6是完全相同的脚本
# connect main(portal site)
: :
# random click (news area)
log('news area random click!!')
driver.find_element_by_css_selector('div.id_news li.ut_item a').click()
log('3sec delay')
time.sleep(3)
# move main(back)
log('move main')
driver.back()
time.sleep(2)
# input keyword1
log('input keyword1 : ' + keyword1)
element = driver.find_element_by_id('query') # is working very well
element.send_keys(keyword1)
element.send_keys(Keys.RETURN)
time.sleep(3)
# random click
log('news click !!!!!')
try:
driver.find_element_by_css_selector('section.sp_nnews ul.list_news li a').click()
except NoSuchElementException:
# if not exists news area
log("blog click!!!")
driver.find_element_by_css_selector('section.sp_ntotal ul.lst_total li a').click()
time.sleep(2) # TODO : 17sec
# move main again
log('move main')
driver.back()
time.sleep(5)
# input keyword2
log('input keyword2 : ' + keyword2)
element = driver.find_element_by_id('query') # is not working :(
element.send_keys(keyword2)
element.send_keys(Keys.RETURN)
time.sleep(3)