0

I am automating a web app on IE(Internet Explorer) browser.

I am getting the below error when I am trying to find any element on the page after the page is loaded.

selenium.common.exceptions.InvalidSelectorException: Message: Unable to locate an element with the xpath expression //div[@id='index_logo']/following-sibling::div/form because of the following error:
TypeError: Object doesn't support property or method 'evaluate';

The code

#xpaths
cpDvForm = "//div[@id='index_logo']/following-sibling::div/form"
cpDvUser = "//input[@id='username']"
cpDvPass = "//input[@id='password']"
cpDvLanRadio = "//input[@id='net_lan']"
cpDvLogin = "//a[@onclick='login()']"
#code
options= webdriver.IeOptions()
d = webdriver.Ie(options=options)
d.get(url)
#time.sleep(10)
#WebDriverWait(d,10).until(EC.element_to_be_clickable(d.find_element(By.XPATH,cpDvUser)))
form = d.find_element(By.XPATH,cpDvForm)
form.find_element(By.XPATH,cpDvUser).clear()
form.find_element(By.XPATH,cpDvUser).send_keys('user')
form.find_element(By.XPATH,cpDvPass).send_keys('pass')
form.find_element(By.XPATH,cpDvLanRadio).click()
form.find_element(By.XPATH,cpDvLogin).click()

I have tried inducing Webdriver wait and sleep waits too,for ensuring page is loaded. I have checked for Iframes and shadow dom. there is neither.

As mentioned, the error occurs when we try to search for any element after page is loaded. All suggestion and solutions are appreciated!!

Additional note/info :

  • I am required to use IE browser
  • Selenium 4.18.0
  • Python 3.12

Let me know if any more information is required will add accordingly. Cheers !

8
  • Please show us what the value is of i.e cpDvUser Commented Apr 5 at 7:54
  • Does this question helps you: stackoverflow.com/questions/75485006/… ? Commented Apr 5 at 7:55
  • Hi @SiebeJongebloed I have added the xpaths above //input[@id='username'] for cpDvUser. I went through the suggested question, didnt help me or If you feel I missed something, kindly add. Thanks ! Commented Apr 5 at 10:21
  • 1
    The XPath is valid. You shouldn't need to find the form and then search from there when the elements have IDs. Have you tried removing the form step and then using the later locators? Do they work? Try something simple for username, (By.ID, "username") instead of the XPath. I'm wondering if you didn't copy/paste that locator from somewhere and got a bad character in the string that isn't visible. Try retyping the cpDvForm locator from scratch.
    – JeffC
    Commented Apr 5 at 15:06
  • 1
    I have no idea. I've tested the XPaths that you provided in the Chrome devtools and get no errors on any of them. The only thing I can think of is what I mentioned earlier... that some stray hidden character got inserted into the locator so that we can't see it but it's causing the error.
    – JeffC
    Commented Apr 9 at 17:35

1 Answer 1

0

As @JeffC highlighted using ID selector By.ID,'theId' works for this. Proceeding with ID selector.

Even though the XPath is correct, due to some miscellaneous reason, it throws the error.

Not the answer you're looking for? Browse other questions tagged or ask your own question.