2

I'm trying to do some webscraping from a betting website:

As part of the process, I have to click on the different buttons under the "Favourites" section on the left side to select different competitions.

Let's take the ENG Premier League button as example. I identified the button as:

Screenshot
(source: 666kb.com)

The XPath is: //*[@id="SportMenuF"]/div[3] and the ID is 91.

My code for clicking on the button is as follows:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


chrome_path = "C:\Python27\Scripts\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)

driver.get("URL Removed")

content = driver.find_element_by_xpath('//*[@id="SportMenuF"]/div[3]')
content.click()

Unfortunately, I always get this error message when I run the script:

"no such element: Unable to locate element: 
{"method":"xpath","selector":"//*[@id="SportMenuF"]/div[3]"}" 

I have tried different identifiers such as CCS Selector, ID and, as shown in the example above, the Xpath. I tried using waits and explicit conditions, too. None of this has worked.

I also attempted scraping some values from the website without any success:

from selenium import webdriver
from selenium.webdriver.common.by import By

chrome_path = "C:\Python27\Scripts\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)

driver.get("URL removed")


content = driver.find_elements_by_class_name('price-val')

for entry in content:
    print entry.text

Same problem, nothing shows up.

The website embeddes an iframe from a different website. Could this be the cause of my problems? I tried scraping directly from the iframe URL, too, which didn't work, either.

I would appreciate any suggestions.

1 Answer 1

2

Sometimes elements are either hiding behind an iframe, or they haven't loaded yet

For the iframe check, try:

driver.switch_to.frame(0)

For the wait check, try:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.XPATH, '-put the x-path here-')))
Sign up to request clarification or add additional context in comments.

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.