mercredi 19 septembre 2018

Can't drag and drop from source to target using selenium and python

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.

This is how containers look: Containers

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: Drivers / Browsers versions

The way i 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(3) > 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.add_argument("--headless")
        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.add_argument("--headless")
        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(1200, 800)
    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.

Thanks.

Aucun commentaire:

Enregistrer un commentaire