1

I am trying to click on a link and can't seem to get it to work. I click all the way up to the page I need, but then it won't click the last link. The code is as follows:

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
import time
from bs4 import BeautifulSoup
import requests

import pandas as pd
import openpyxl
from password import DKpassword
#import SendKeys

beginningTime = time.time()
browser = webdriver.Chrome()
browser.get('https://www.draftkings.com/lobby')
browser.maximize_window()
time.sleep(5)
signinLink = browser.find_element_by_xpath("""//*[@id="react-mobile-home"]/section/section[2]/div[2]/div[3]/div/input""")
signinLink.click()
signinLink.send_keys("abcdefg")
signinLink.send_keys(Keys.TAB)
passwordLink = browser.find_element_by_xpath("""//*[@id="react-mobile-home"]/section/section[2]/div[2]/div[4]/div/input""")
passwordLink.send_keys(DKpassword)
passwordLink.send_keys(Keys.ENTER)
time.sleep(5)

if browser.current_url == "https://www.draftkings.com/account/sitelogin/false?returnurl=%2Flobby1":
    signin = browser.find_element_by_partial_link_text("SIGN IN")
    signin.click()
elif browser.current_url == "https://www.draftkings.com/lobby#/featured":

    mlbLink = browser.find_element_by_partial_link_text("MLB")
    mlbLink.click()
else:
    print("error")

time.sleep(5)
featuredGame = browser.find_element_by_class_name("GameSetTile_tag")
featuredGame.click()
time.sleep(5)
firstContest = browser.find_element_by_partial_link_text("Enter")
firstContest.click()

I receive the error message that the element is not clickable at point... and another element would receive the click. Any help would be greatly appreciated. I don't care which contest is clicked on as long as it is on the featured page which the previous code directs it too.

HTML code Webpage screenshot

2
  • I don't know if it has anything to do with their being multiple "Enter" buttons on the page but I don't know how to tell it to grab the first available one on the page. Commented Jun 20, 2018 at 2:17
  • Instead of "browser.find_element_by_partial_link_text("enter")",you can Use "browser.find_element_by_link_text("enter")". Hope this will help you. Commented Jun 20, 2018 at 4:32

3 Answers 3

2

There can be multiple reasons for that.

1. You might have to scroll down or might have to perform some action so that it'll be visible to script.

for scroll down you can use this code :

browser.execute_script("window.scrollTo(0, Y)")

where Y is the height (on a fullhd monitor it's 1080)

2. There can be multiple web element present , in this case you have to use unique element from dom , you can check that by right click > inspect > under element section > CTRL+F > write your locator (in your case xpath) to check how many entries are present.

You can try with this xpath also :

//a[contains(text(),'Enter') and contains(@href,'/contest/draftteam') and contains(@class,'dk-btn-dark')]  

Code :

WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//a[contains(text(),'Enter') and contains(@href,'/contest/draftteam') and contains(@class,'dk-btn-dark')]"))

firstContest = browser.find_element_by_xpath("//a[contains(text(),'Enter') and contains(@href,'/contest/draftteam') and contains(@class,'dk-btn-dark')]")
firstContest.click()
Sign up to request clarification or add additional context in comments.

2 Comments

I'm still learning Python but I should have been able to figure out the error myself!! I first used the scroll down approach and found another link that contained "Enter" so it was trying to click that but of course it wasn't visual so it was throwing that error that it wasn't clickable. Once I realized that, I used the //a contains to look for /draftteam and then it worked perfectly. Thanks for your help!
@ShawnSchreier : No problem mate.
1

Replace click event with action class, which will solve this Exception

from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver)
actions.move_to_element(firstContest).click().perform()

Comments

0

I was able to overcome this exception by using Click through JavaScript executor instead of regular Element.click(), as below-

WebElement element = webDriver.findElement(By.xpath(webElemXpath));
try {

    JavascriptExecutor ex = (JavascriptExecutor) webDriver;
    ex.executeScript("arguments[0].click();", element);
    logger.info(elementName was + " clicked");
} 
catch (NoSuchElementException | TimeoutException e) {
logger.error(e.getMessage());

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.