I am getting error AttributeError on action.drag_and_drop_by_offset by using Page Object Model on setSignature.
from selenium.webdriver.common.action_chains import ActionChains
class SignaturePage:
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()
CodePudding user response:
Issue is present here
drag_and_drop_by_offset(box, 200, 0)
you are passing box
which is a list of web element
, not a single web element since you've used find_elements
here box = self.driver.find_elements_by_xpath(self.canvas)
Just change that to find_element
and you should be good to go.
Note:
find_elements : returns a list of web element.
find_element : returns a single web element.