python-3.x - 为什么我收到 TypeError:'ActionChains' 对象不可迭代
问题描述
当我运行下面的代码时,我收到错误“TypeError: 'ActionChains' object is not iterable”。我究竟做错了什么?
回溯(最近一次通话最后):文件“/Users/Albert/Automation/online-tests/drawingTest.py”,第 55 行,在 test_onlineTest self.test_drawGreenPencil() 文件“/Users/Albert/Automation/online-tests/drawingTest .py",第 147 行,在 test_drawGreenPencil self.draw_lines(action, [(60, -30), (40, 30), (-40, 30), (-60, -30)]) 文件 "/Users/ Albert/Automation/online-tests/drawingTest.py",第 59 行,draw_lines 中的 o 偏移量:TypeError:'ActionChains' 对象不可迭代
这是代码片段:
def draw_lines(action, offsets, scale=1):
for o in offsets:
action.click_and_hold()
action.move_by_offset(scale * o[0], scale * o[1])
action.release().perform()
def test_drawGreenPencil(self):
#click free hand pencil icon
self.driver.find_element(*MainPageLocators.freeHandPencil).click()
print("\n" + "Click free hand pencil icon...OK")
# click line or pen color picker icon
self.driver.find_element(*MainPageLocators.penColorPicker).click()
# click the green color from the color pallete sub menu
self.driver.find_element_by_css_selector(
".line-colors [data-color='brown']").click()
time.sleep(2)
print ("Start drawing...")
# Start mouse interactions
action = ActionChains(self.driver)
action.move_to_element(self.driver.find_element_by_css_selector('canvas.upper-canvas')).perform()
self.draw_lines(action, [(-30, 60), (30, 40), (30, -40), (-30, -60)])
self.draw_lines(action, [(60, -30), (40, 30), (-40, 30), (-60, -30)])
self.draw_lines(action, [(-30, -60), (30, -40), (30, 40), (-30, 60)])
self.draw_lines(action, [(-60, -30), (-40, 30), (40, 30), (60, -30)])
self.draw_lines(action, [(-30, 60), (30, 40), (30, -40), (-30, -60)], 0.8)
self.draw_lines(action, [(60, -30), (40, 30), (-40, 30), (-60, -30)], 0.8)
self.draw_lines(action, [(-30, -60), (30, -40), (30, 40), (-30, 60)], 0.8)
self.draw_lines(action, [(-60, -30), (-40, 30), (40, 30), (60, -30)], 0.8)
self.draw_lines(action, [(-30, 60), (30, 40), (30, -40), (-30, -60)], 0.6)
self.draw_lines(action, [(60, -30), (40, 30), (-40, 30), (-60, -30)], 0.6)
self.draw_lines(action, [(-30, -60), (30, -40), (30, 40), (-30, 60)], 0.6)
self.draw_lines(action, [(-60, -30), (-40, 30), (40, 30), (60, -30)], 0.6)
print ("Done.")
time.sleep(20)
解决方案
您已经执行了该操作。请重新创建它。
def draw_lines(self, offsets, scale=1):
for o in offsets:
action = ActionChains(self.driver)
action.click_and_hold()
action.move_by_offset(scale * o[0], scale * o[1])
action.release().perform()
def test_drawGreenPencil(self):
...
self.draw_lines(self, [(-30, 60), (30, 40), (30, -40), (-30, -60)])
推荐阅读
- ios - UITabBar 图标未正确显示
- ios - SKStoreReviewController requestReview 方法需要时间来显示并且应用程序卡住,直到出现 ReviewController
- angular - 以角度在特定行上应用样式
- docker - 在 docker 构建时启用 ssh
- php - WooCommerce 条件产品字段
- angular - 服务工作者如何与子域一起工作?
- vba - 发送 HTTP-Post 请求以在 VBA 中填写表格
- angularjs - 从AngularJS中父控制器上的子控制器访问文件项
- python - 训练深度学习代码时的结果
- c - C中的缓冲区溢出攻击 - 无法覆盖堆栈