0

hope everyone is well.

I've been trying to automate a form entry by using Selenium. I've used it before and never had an issue with locating the web elements. I can't seem to locate the form text entry fields as web elements, regardless of the method I use. I tried, XPATH, NAME, CSS SELECTOR, nothing works.

The web page address is

https://ee.conifr.com.au/single/9KKQb0af?ref=12_27_32

The code I am using is (these are the different options I've tried to locate the first text entry in the form):

element = self.browser.find_element(By.XPATH,'//[@id="aHjEbzEsTogismYtToxncr"]/section[2]/section/label[2]/input')

OR

element = self.browser.find_element(By.NAME,'/aHjEbzEsTogismYtToxncr/scope1_fuel/unique_vehicle_id')

Error msg is:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="aHjEbzEsTogismYtToxncr"]/section[2]/section/label[2]/input"}

Any help/guidance would be greatly appreciated.

Thanks!

1
  • Both of the selectors you mentioned above are invalid but the one mentioned in error message is correct and works, still you should avoid using xpaths with indexes and I am assuming you want to enter data into Unique Vehicle ID field, then try this //span[text()="Unique Vehicle ID"]//following-sibling::input Commented May 4, 2023 at 6:24

1 Answer 1

0

The Name attribute of the input tag contains unique_vehicle_id. Have used the same to build Xpath for that element.

//input[contains(@name,'unique_vehicle_id')]

And need to use some waits, either Implicit waits or Explicit waits to locate and interact with the element.

  1. With Implicit waits
# Imports required
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
import time

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.implicitly_wait(10)

driver.get("https://ee.conifr.com.au/single/9KKQb0af?ref=12_27_32")

input1 = driver.find_element(By.XPATH,"//input[contains(@name,'unique_vehicle_id')]")
input1.send_keys("unique id")
time.sleep(5) # just to see if the text was entered in the field
  1. With Explicit waits
#Imports required for Explicit waits
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver.get("https://ee.conifr.com.au/single/9KKQb0af?ref=12_27_32")

wait = WebDriverWait(driver,30)
input1 = wait.until(EC.element_to_be_clickable((By.XPATH,"//input[contains(@name,'unique_vehicle_id')]")))
input1.send_keys("unique id")
time.sleep(5)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.