Mathlearner
Mathlearner

Reputation: 117

Python selenium "Timeout Exception" error

I am trying to click on the Financials link of the following URL using Selenium and Python.

https://www.marketscreener.com/DOLLAR-GENERAL-CORPORATIO-5699818/

initially I used the following code

link = driver.find_element_by_link_text('Financials')
link.click()

Sometimes this works and sometimes it doesn't and I get the Element is not Clickable at point (X,Y) error. I have added code to maximise the webpage in case the link was getting overlapped by something.

It seems that the error is because the webpage doesn't always load in time. To overcome this I have been trying to use expected conditions and wait libraries of Selenium.

I came up with the following but it isn't working, I just get TimeoutException.

link = wait(driver, 60).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="zbCenter"]/div/span/table[3]/tbody/tr/td/table/tbody/tr/td[8]/nobr/a/b')))
link.click()

I think XPATH is probably the best choice here or perhaps class name, but there is no ID. I'm not sure if its because the link is inside some table that it isn't working, but it seems odd to me that sometimes it works without having to wait at all.

I have tried Jacob's approach. The problem is I want it to be dynamic so it will work for other companies. Also, when I first land on the summary page the URL has other things at the end so I can't just append /financials to the URL.

This is the URL it gives me: https://www.marketscreener.com/DOLLAR-GENERAL-CORPORATIO-5699818/?type_recherche=rapide&mots=DG

I might have find a way around this:

link = driver.current_url.split('?')[0] 

How do I then access this list item and append the string 'financial/' to the list item?

Upvotes: 0

Views: 116

Answers (1)

jda5
jda5

Reputation: 1446

I was looking for a solution when I noticed that clicking on the financial tab takes you to a new URL. In this case I think the simplest solution is just to use the .get() method for that URL.

i.e.

 driver.get('https://www.marketscreener.com/DOLLAR-GENERAL-CORPORATIO-5699818/financials/')

This will always take you directly to the financial page! Hope this helps.

Upvotes: 2

Related Questions