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 :
Let me know if any more information is required will add accordingly. Cheers !
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.