1

I've never studied HTML seriously, so probably what I'm going to say is not right.

While I was writing my selenium code, I noticed that some buttons on some webpages does not redirect to other pages, but they change the structure of the the first one. From what I've understood, this happens because there's some JavaScript code that modifies it.

So, when I wanna get some data which is not present on the first page loading, I just have to click the right sequence of button to obtain it, rigth?

The page I wanted to load is https://watch.nba.com/, and what I want to get is the match list of a given day. The fastest path to get it is to open the calendary:

calendary = driver.find_element_by_class_name("calendar-btn")
calendary.click() 

and click the selected day:

page = calendary.find_element_by_xpath("//*[contains(text(), '" + time.strftime("%d") + "')]")

page.click()

running this code, I get this error:

selenium.common.exceptions.ElementNotVisibleException

I read somewhere that the problem is that the page is not correctly loaded, or the element is not visible/clickable, so I tried with this:

wait = WebDriverWait(driver, 10)

page = wait.until(EC.visibility_of_element_located((By.XPATH, "//*[contains(text(), '" + time.stfrtime("%d") + "')]")))
page.click()

But this time I get this error:

selenium.common.exceptions.TimeoutException

Can you help me to solve at least one of these two problems?

2
  • Do you have to log in first? I'm not seeing any elements with class "calendar-btn" on the home page. Commented Mar 27, 2017 at 20:18
  • No, it is the class of the "calendar" button, on the upper left corner, under the "log-in" button @JeffC Commented Mar 27, 2017 at 20:27

1 Answer 1

1

The reason you are getting such behavior is because this page is loaded with iFrames (I can see 15 on the main page) once you click the calendar button, you will need to switch your context to either be on the defaultContext or a specific iframe where the calendar resides. There is tons of code outthere that shows you how to switch into and out of iframe. Hope this helps.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm trying to find out which is the iframe I need, but all 15 seem not to be raleted with the calendar...
try switching to default context once you open up the calendar :) The calendar button is inside an iframe, but the calendar view loads in default context
I can't believe it, but it's finally working!!! I've spent like 3 hours on this problem, and the solution was just one line long. Really thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.