I am attempting to use Python and Selenium to re-order the players in my fantasy football team's Pre-Draft Strategy page. Logging in and getting to the page is fine, but attempting to swap the players around is causing some issues.
So far I have used the following code but without success:
import nfl_useful_functions as nfl
from selenium.webdriver import ActionChains
import time
## Login to ESPN
driver = nfl.login2espn()
## Go to draft strategy page
driver.get("http://fantasy.espn.com/football/editdraftstrategy?leagueId=123456")
## Wait 10 seconds
time.sleep(10)
## Choose the player to be dragged (player 1)
draggable = driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/div[5]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/section[1]/table[1]/tbody[1]/tr[1]/td[1]/div[1]/div[1]/div[2]/table[1]/tbody[1]/tr[1]/td[1]/div[1]/table[1]/tbody[1]/tr[1]")
## Choose the player for player 1 to be dragged onto (and swapped with)
droppable = driver.find_element_by_xpath("/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/div[5]/div[2]/div[1]/div[1]/div[2]/div[2]/div[1]/div[2]/section[1]/table[1]/tbody[1]/tr[1]/td[1]/div[1]/div[1]/div[2]/table[1]/tbody[1]/tr[1]/td[1]/div[1]/table[1]/tbody[1]/tr[2]")
## Drag and drop
#Attempt 1
ActionChains(driver).drag_and_drop(draggable, droppable).perform()
#Attempt 2
ActionChains(driver).drag_and_drop_by_offset(draggable, 0, 40).perform()
#Attempt 3
ActionChains(driver).click_and_hold(draggable)\
.move_to_element(droppable)\
.release(draggable)\
.perform()
#Attempt 4
ActionChains(driver).click_and_hold(draggable)\
.move_to_element_with_offset(draggable,0,40)\
.release(draggable)\
.perform()
## Wait 5 seconds
time.sleep(5)
## Close driver
driver.close()
I have tried each of the different attempts (individually) but the only (small) positive is that the player I'm trying to move does appear to be selected:
But nothing actually comes of this. The script runs successfully (by that I mean without error) each time. The player I'm trying to drag goes grey, as above, for a two or three seconds, then seems to give up and the script ends. No exceptions or anything.
Is there anything else I can try? Ideally it would still be in Python other than that I'm very open to any suggestions! If it's useful, according to Wappalyzer,
the details of the page in question are:
EDIT
This is how the page looks when I swap players over manually. This is how the page looks when I run the script above (Attempt 1).
EDIT 2
I have created a throwaway account on ESPN in order to make recreation of the problem easier. Login to ESPN Fantasy using od44@live.co.uk & Pa55word123 and then go to the Pre-Draft Strategy Page.