0

I want to login to the following website:

https://www.investing.com/equities/oil---gas-dev-historical-data

Here is what I have tried so far:

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", './ogdc.csv')
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")

driver = webdriver.Firefox(firefox_profile=profile)
driver.get('https://www.investing.com/equities/oil---gas-dev-historical-data')
driver.find_element_by_class_name("login bold")
driver.find_element_by_id('Email').send_keys('myemail')
driver.find_element_by_id('Password').send_keys('mypass')
driver.find_element_by_partial_link_text("Download Data").click()

But I get following Exception:

NoSuchElementException

How can I login to the above website?

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. Commented Mar 18, 2020 at 8:06

2 Answers 2

1

You need click Sign in first to bring up the login popup, try the following code:

driver.get('https://www.investing.com/equities/oil---gas-dev-historical-data')
driver.find_element_by_css_selector("a[class*='login']").click()
driver.find_element_by_id('loginFormUser_email').send_keys('myemail')
driver.find_element_by_id('loginForm_password').send_keys('mypass')
driver.find_element_by_xpath("//div[@id='loginEmailSigning']//following-sibling::a[@class='newButton orange']").click()
Sign up to request clarification or add additional context in comments.

Comments

0

From what I can tell, you need to click the Sign In button („login bold”) in order to open the popup. That one is not part of the initial DOM load and need some time to show up. So basically, wait for #Email and #Password to get visible.

You should be able to use an explicit wait for this.

2 Comments

But it gives error on this line: driver.find_element_by_class_name("login bold")
I just replicated locally: selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .login bold. The selector must be .login.bold (that is, an element with both classes). driver.find_element_by_class_name("login.bold") works for me.

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.