When I run the code below, I get selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="i0"]/input"}
(Session info: chrome=83.0.4103.97)
.
However, in my terminal I can access the required element:
>>> steam_pressure_field = browser.find_element_by_xpath('//*[@id="i0"]/input')
>>> steam_pressure_field.get_attribute('value')
'0'
As you can see in the comment section of the code, I have tried waiting for a delay of 3 seconds to see if that made a difference. However, after doing this several times, the page stopped loading when I used the delay (maybe some anti-bot feature?)
So I'm trying to understand what is going on here, and how I can successfully access the fields I require. Is there something I am missing please?
BTW, The div
IDs don't seem to be dynamic.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36'
options = webdriver.ChromeOptions()
options.add_argument(f'user-agent={user_agent}')
browser = webdriver.Chrome(options=options)
url = 'https://www.tlv.com/global/US/calculator/superheated-steam-table.html?advanced=off'
# delay = 3
# try:
# wait = WebDriverWait(browser, delay)
# wait.until(EC.presence_of_element_located((By.ID, "body")))
# browser.get(url)
# print("Page is ready")
# except TimeoutException:
# print("Loading took too much time")
browser.get(url)
steam_pressure_field = browser.find_element_by_xpath('//*[@id="i0"]/input')
print(steam_pressure_field.get_attribute('value'))