Home > other >  Help: selenium ActionChains perform () error problem
Help: selenium ActionChains perform () error problem

Time:11-18

Learn a simple drag-and-drop action, the same code
The from the selenium import webdriver
The from the selenium. Webdriver import ActionChains
# interactive action
Browser=webdriver. Chrome ()
Url="http://www.runoob.com/try/try.php? Filename=jqueryui - API - droppable
"The get (url)
The switch_to. Frame (' iframeResult ')
Source=the find_elements_by_css_selector (' # draggable)
Target=the find_elements_by_css_selector (' # droppable)
The actions=ActionChains (browser)
Actions. Drag_and_drop (source and target)
Actions. The perform ()
Appear the following error, didn't understand, ask the great spirit show
Traceback (the most recent call last) :
The File "D:/Programming Practice/Crawler/test_selenium/test_04 py", line 12, the in & lt; module>
Actions. The perform ()
The File "C: \ Users \ \ AppData acm/Local/designed/Python \ Python36 \ lib \ site - packages, selenium and webdriver \ common \ action_chains py", line 83, perform in
The action ()
The File "C: \ Users \ \ AppData acm/Local/designed/Python \ Python36 \ lib \ site - packages, selenium and webdriver \ common \ action_chains py", line 293, in & lt; Lambda>
Command MOVE_TO, {' element: to_element. Id}))
AttributeError: 'list' object has no attribute 'id'
Do not add the last sentence actions. The perform () is no drag and drop action is not an error,

CodePudding user response:

Find_elements get is not the driver object, which are stored in a list of objects, and perform the event object is supposed to be a driver object, so you should to deal with result of find_elemenets, access to specific objects, and then for the back operation

CodePudding user response:

Should have a much find_element_by_css_selector, a s

CodePudding user response:

With q, similar to, but not the same as
Driver=webdriver. Chrome ()
Driver. The get (" https://www.baidu.com/")
Driver. Find_element_by_xpath ("//* [@ id=\ \ "lg"]/map/area ")
# # driver. Find_element_by_css_selector (" lg & gt; The map & gt; Area ")
CCL=ActionChains (driver)
CCL. Context_click (driver)
CCL. Send_keys (Keys. ARROW_DOWN)
CCL. Send_keys (Keys. ENTER)
CCL. The perform ()
# ActionChains (driver). Context_click (driver). The perform ()
# CCL. Send_keys (Keys. ARROW_DOWN). Send_keys (Keys. ENTER). The perform ()
Time. Sleep (3)
Driver. The quit ()

And CCL. The perform () is an error, don't add, don't complain doesn't step, does excuse me the great spirit of doing to answer

CodePudding user response:

It is possible that positioning to the element is not the only cause

CodePudding user response:

Look at the last line of an error, you will know why: AttributeError: 'list' object has no attribute 'id'

Source=the find_elements_by_css_selector (' # draggable)
Target=the find_elements_by_css_selector (' # droppable)

The two is find_element not find_element s , don't need to add s
  • Related