Created
November 12, 2013 17:36
-
-
Save reynish/7435208 to your computer and use it in GitHub Desktop.
Python Selenium Drag and Drop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from selenium import webdriver | |
from selenium.webdriver import ActionChains | |
from selenium.webdriver.common.keys import Keys | |
from selenium.common.exceptions import NoSuchElementException | |
import time | |
baseUrl = 'http://jsbin.com/afica/13344' | |
class DragAndDropTest(unittest.TestCase): | |
def setUp(self): | |
# self.driver = webdriver.PhantomJS('C:\Testing\phantomjs-1.9.2\phantomjs.exe') | |
self.driver = webdriver.Chrome() | |
def test_sd_draganddrop(self): | |
driver = self.driver | |
driver.get(baseUrl) | |
# Now for the drag and drop! | |
element = driver.find_element_by_css_selector("#jackosborne") | |
target = driver.find_element_by_css_selector("#drop") | |
driver.implicitly_wait(0.5) | |
action_chains = ActionChains(driver) | |
# action_chains.move_to_element(element).click_and_hold(element).move_to_element(target).perform() | |
action_chains.drag_and_drop(element, target).perform() | |
try: | |
driver.find_element_by_css_selector("#drop p a") | |
except NoSuchElementException: | |
assert 0, "No a in the p" | |
def tearDown(self): | |
driver = self.driver | |
self.driver.close() | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for clear coding. Can we upload an image to Facebook? I tried but it is not working. Can you help me how to handle this issue?