selenium drag drop

教程上拖拽

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
driver = webdriver.Firefox()
driver.get("http://cn.bing.com/")

sleep(10)
# 定位到“学术”元素的原位置
element = driver.find_element_by_xpath("//*[@id='scpl1']")

#selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id='scpl1']

# 定位到元素要移动到的目标位置,目标是搜索框
target = driver.find_element_by_xpath("//*[@id='sb_form_q']")
#//*[@id="sb_form"]/div
#//*[@id='sb_form_q']
ActionChains(driver).drag_and_drop(element,target).perform()

sleep(10)
driver.quit()

结果总是出不来
成功就是这个画面
上传中.![drag drop.png

失败就
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id='scpl1']

为什么?
是我的问题吗 ?

阅读 727
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题