I’m currently learning Selenium automation and I’m trying to automate a simple task:
- navigating to a webpage, (https://sri-gpt.github.io)
- locating an input field,
- entering text into it, and submitting the form.
To achieve this, I’m using Python and Selenium WebDriver.
Here’s the code I’ve written:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://sri-gpt.github.io")
# Find the form field using its XPath
form_field = driver.find_element("xpath", '/html/body/flutter-view/flt-text-editing-host/form/input[1]')
form_field.send_keys("MyInput_123")
driver.quit()
However, when I execute this code, I encounter the following error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/flutter-view/flt-text-editing-host/form/input[1]"}
It seems that my XPath
expression to locate the input field is incorrect. I’ve tried different variations, but none seem to work. Can anyone help me correct my XPath expression to successfully locate the input field on the webpage?
Additionally, if there are any best practices or alternative methods for locating elements using Selenium WebDriver, I’d appreciate any advice or suggestions.
Selenium version: 4.18.1
Python version: 3.10.12
Ubuntu version: 22.04
Chrome version: 22.0.6261.128 (Official Build) (64-bit)
Thank you!
2
Answers
Use below xpath to type into textbox
You can use XPath or chropath chrome extension to find the exact element.