AttributeError: move_to requires a WebElement
AttributeError: move_to requires a WebElement
我在 action.drag_and_drop_by_offset 上使用 setSignature 上的页面对象模型时遇到错误 AttributeError。
从 selenium.webdriver.common.action_chains 导入 ActionChains
class 签名页:
signatureCanvas = "canvas_signature"
btn_go_back = "//*[@id='mobile-wrapper']/main/section/a"
btn_draw_signature = "//*[@id='mobile-wrapper']/main/article[1]/div[2]/div[1]/div[1]/a"
canvas = "//*[@id='canvas_signature']"
def __init__(self, driver):
self.driver = driver
def btngoBack(self):
self.driver.find_element_by_xpath(self.btn_go_back).click()
def btnDrawSignature(self):
self.driver.find_element_by_xpath(self.btn_draw_signature).click()
def setSignature(self):
box = self.driver.find_elements_by_xpath(self.canvas)
action = ActionChains(self.driver)
action.drag_and_drop_by_offset(box, 200, 0)
action.perform()
此处存在问题
drag_and_drop_by_offset(box, 200, 0)
您传递的 box
是 list of web element
,而不是 单个 Web 元素,因为您在这里使用了 find_elements
box = self.driver.find_elements_by_xpath(self.canvas)
只需将其更改为 find_element
,您就可以开始了。
注:
find_elements : returns a list of web element.
find_element : returns a single web element.
我在 action.drag_and_drop_by_offset 上使用 setSignature 上的页面对象模型时遇到错误 AttributeError。
从 selenium.webdriver.common.action_chains 导入 ActionChains
class 签名页:
signatureCanvas = "canvas_signature"
btn_go_back = "//*[@id='mobile-wrapper']/main/section/a"
btn_draw_signature = "//*[@id='mobile-wrapper']/main/article[1]/div[2]/div[1]/div[1]/a"
canvas = "//*[@id='canvas_signature']"
def __init__(self, driver):
self.driver = driver
def btngoBack(self):
self.driver.find_element_by_xpath(self.btn_go_back).click()
def btnDrawSignature(self):
self.driver.find_element_by_xpath(self.btn_draw_signature).click()
def setSignature(self):
box = self.driver.find_elements_by_xpath(self.canvas)
action = ActionChains(self.driver)
action.drag_and_drop_by_offset(box, 200, 0)
action.perform()
此处存在问题
drag_and_drop_by_offset(box, 200, 0)
您传递的 box
是 list of web element
,而不是 单个 Web 元素,因为您在这里使用了 find_elements
box = self.driver.find_elements_by_xpath(self.canvas)
只需将其更改为 find_element
,您就可以开始了。
注:
find_elements : returns a list of web element.
find_element : returns a single web element.