I am trying to drag and drop using Python and Selenium.
I have two containers with rows which indicate file names and by drag and drop, I want to transfer one file from the first container to the second one.
I have seen on the internet that selenium and drag and drop libraries had some issues and I am not really sure how to make this work.
As the version of browsers and drivers play an important role, please have a look at the ones I am using:
The way am trying to drag and drop is the following:
time.sleep(15)
source_element = self.browser.find_element_by_css_selector('#transfer-tape-listing-nst0 > tbody > tr.file.transfer-tape-item.ui-draggable.ui-draggable-handle > td.listing-name')
dest_element = self.browser.find_element_by_css_selector('#transfer-location-listing > tbody > tr:nth-child(1) > td.listing-name.ui-droppable > span.listing-name-label')
ActionChains(self.browser).drag_and_drop(source_element, dest_element).perform()
My driver has this configuration:
def set_up_browser():
display = Display(visible=0, size=(1200, 800))
display.start()
selected_browser = config_section_map('Test')['browser']
browser = ''
if selected_browser == 'Firefox':
opts = FirefoxOptions()
opts.set_headless(headless=False)
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", False)
firefox_profile.set_preference("marionette", True) # remove if causing issues
browser = webdriver.Firefox(executable_path="/usr/bin/drivers/geckodriver", firefox_profile=firefox_profile, firefox_options=opts)
elif selected_browser == 'Chrome':
opts = ChromeOptions()
opts.set_headless(headless=False)
opts.add_argument("--no-sandbox")
opts.add_argument("--incognito")
browser = webdriver.Chrome(executable_path="/usr/bin/drivers/chromedriver", chrome_options=opts)
elif selected_browser == 'edge':
pass
else:
print 'unsupported browser'
exit
browser.set_window_size(1600, 1000)
# browser.maximize_window()
browser.delete_all_cookies()
browser.implicitly_wait(int(config_section_map('Test')['wait']))
browser.refresh()
return browser
Can someone help me please with resolving this using Python? I have tried with both drivers and both fail. I don't get any exception, but the action doesn't work.
What happens is that the driver clicks on the source element and hovers on the target.
This is how containers look after executing the script:
Thanks.
WebDriverException: Message: unknown error: failed to change window state to maximized, current state is normal
when the script tries to executebrowser.maximize_window().
If i comment the line for maximizing my script fails in general because the screen is to small and many elements are hidden or on top of other elements.opts.add_argument("--start-maximized")