Hello i have written this script to try to automate login process to the eToro server and after that grab the profit and equity values of the portfolio server.
def get_profit():
profit = equity = ''
try:
options = webdriver.ChromeOptions()
options.add_argument('--headless') # Runs Chrome in headless mode.
options.add_argument('--no-sandbox') # Bypass OS security model
options.add_argument('--disable-automation')
options.add_argument('--disable-extensions')
# Create new session
driver = webdriver.Chrome( options=options, executable_path='/usr/bin/chromedriver' )
driver.get( 'https://etoro.com/portfolio' )
time.sleep(2)
driver.find_element_by_id('username').send_keys('my_username')
driver.find_element_by_id('password').send_keys('my_password')
driver.find_element_by_css_selector('button.ng-binding').click()
time.sleep(2)
driver.save_screenshot( 'static/img/etoro.png' )
profit = driver.find_element_by_xpath( '/html/body/ui-layout/div/div/footer/et-account-balance/div/div[5]/span[1]' ).text
equity = driver.find_element_by_xpath( '/html/body/ui-layout/div/div/footer/et-account-balance/div/div[7]/span[1]' ).text
driver.quit()
except Exception as e:
profit = repr(e)
return profit, equity
Problem is that iam constantly getting the same error message which is NoSuchElementException('no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/ui-layout/div/div/footer/et-account-balance/div/div[5]/span[1]"}\n (Session info: headless chrome=86.0.4240.22)', None, ['#0 0x55a2e8090d99 ', ''])
You can see this output if you try to run my web app script at http://superhost.gr/portfolio Before some days this script was able to grab these 2 values by running successfully once in every half hour or so, the rest of the times was failing to....but now that i speak it cannot longer access the website at all and i don't know why.