'Unable to locate element: {"method":"xpath","selector":"//input[@id='fieldname3_1']"}

Wanted to locate an element with python selenium 4. My code:

x = s.find_element(By.XPATH,"//input[@id='fieldname3_1']")

https://thearbacademy.com/arbitrage-betting-calculator/

link for page

Trying to locate this

The HTML looks like

<input aria-label="" id="fieldname3_1" name="fieldname3_1" class="field number large valid" type="text" value="" aria-invalid="false">

My error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@id='fieldname3_1']"}


Solution 1:[1]

Check the id value, also use WebDriveWait for the elements to load.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

myElem = WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.ID, 'fieldname2_1')))
#myElem.send_keys("123")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vignesh