Reputation: 345
I am new to selenium and I am trying to get the rate with the specific date I input from this site:OANDA. For example, Send_Keys with '2019-09-06' and the ask-average rate of USD-EUR is 0.90588.
It works fine without headless and the result is correct. However, when I add headless option in, Send_Keys fails and it returns the ask-average rate today, which is not what I want.
This program will execute on Linux server later so I have to add headless into the script. How to solve this problem?
Thanks.
chrome version: 75.0.3770.80 python: 3.6.5 Linux: Red Hat Enterprise Linux Server release 7.4 (Maipo)
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import pandas as pd
from selenium.webdriver.common.keys import Keys
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument('--window-size=1920x1080')
chrome_options.add_argument('--disable-gpu')
chrome_path = 'D://work/chromedriver.exe'
driver = webdriver.Chrome(chrome_path,chrome_options=chrome_options)
#start to crawl
driver.get('https://www1.oanda.com/currency/converter/')
time.sleep(1)
end_date_input = driver.find_element_by_id('end_date_input')
end_date_input.send_keys(Keys.CONTROL + 'a')
time.sleep(1)
end_date_input.send_keys(Keys.DELETE)
time.sleep(1)
end_date_input.send_keys('2019-09-06')
time.sleep(1)
end_date_input.send_keys(Keys.ENTER)
time.sleep(1)
soup = BeautifulSoup(driver.page_source, 'html.parser')
table_soup= soup.findAll('tr',{'class':'body'})[1]
bidAskAskAvg = round(float(table_soup.findAll('td')[4].text),8)
print(bidAskAskAvg)
expected: 0.90588, but it returns: 0.90721 (I don't want it.)
Upvotes: 0
Views: 490
Reputation: 142641
On Linux Mint I get wrong result in both situations - with and without headless
- but I can see that it expects date in American format MM/DD/YYYY
- '09/06/2019'
.
If I use '09/06/2019'
then I get correct result with and without headless
.
Upvotes: 1