1

I have webpage where I am trying to login to it. When I use find element by name method to find the elements I get element not interactable error but when i use find element by xpath it works fine and no error. Can anyone explain me why it is not able to interact with element when found by name method?

Same issue is observed for User ID, Password and Login elements. I am sure even when using by name method website is loaded and is ready for use. Below is the screenshot of the Webpage login

enter image description here

My HTML code is as below

enter image description here

Below is the code am using

import xlrd
    import openpyxl
    import requests
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import time
    from selenium.webdriver.support.ui import Select
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver import ChromeOptions, Chrome
    opts = webdriver.ChromeOptions()
    opts.add_experimental_option("detach", True)
    
    def login_to_Portal(mBrowser):
        mBrowser.find_element_by_id("userNameTrucks")
        mBrowser.find_element_by_id("userNameTrucks").clear()
        mBrowser.find_element_by_id("userNameTrucks").send_keys("xxxxx")
        mBrowser.find_element_by_xpath("/html/body/div/router-view/section/div[2]/ul/li[4]/input")
        #mBrowser.find_element_by_name("password").clear()
        mBrowser.find_element_by_xpath("/html/body/div/router-view/section/div[2]/ul/li[4]/input").send_keys("xxxxx")
        mBrowser.find_element_by_xpath("/html/body/div/router-view/section/div[2]/ul/li[5]/button").click()
        #mBrowser.find_element_by_class_name("au-target").click()
        #mBrowser.find_element_by_name("target")
        #mBrowser.find_element_by_name("target").click()
    
    mBrowser = webdriver.Chrome(executable_path = r'C:\chromedriver_win32\chromedriver.exe', options = opts )
    mBrowser.get("https://grouptrucksportal.volvo.com/gpp/index.html")
    time.sleep(10)
    mBrowser.find_element_by_xpath("/html/body/div/compose[1]/section/div[1]/map/area[1]")
    
    mBrowser.find_element_by_xpath("/html/body/div/compose[1]/section/div[1]/map/area[1]").click()
    time.sleep(3)
    mBrowser.find_element_by_xpath("/html/body/div/compose[3]/section/div[2]/div/ul/li[4]/a")
    mBrowser.find_element_by_xpath("/html/body/div/compose[3]/section/div[2]/div/ul/li[4]/a").click()
    time.sleep(5)
    login_to_Portal(mBrowser)

Now am using xpatha and everything works fine. When i use find element by name it fails with not interactable error

4
  • Can you share your code pls? Commented Jul 20, 2020 at 10:03
  • Adding image of code is bad practice no one will write that for you from image. Consider to add the code not the image of code. Please read minimal reproducible example and follow it in your all posts Commented Jul 20, 2020 at 10:25
  • @Dev I have not added code here, i have images of website and HTML code. This is company internal tool and we are not supposed to share complete HTML code of the wepage. Hope you understand. Commented Jul 20, 2020 at 10:33
  • @Gokul nath, I have added the code please have a look Commented Jul 20, 2020 at 10:34

1 Answer 1

1

This error message...

ElementNotInteractableException: Message: element not interactable

...implies that the WebElement with whom you are trying to interact isn't interactable (isn't in interactable state) at that moment.

The two(2) main reasons for this error are:

  • Either you are trying to interact with a wrong/mistaken element.
  • Or you are invoking click() too early even before the element turns clickable / interactable.

Analysis and Solution

There are a couple of things you need to take care. In case of websites like Truck Dealer Online once you navigate to the Login page instead of find_element_by_id() or find_element_by_name() you have to induce WebDriverWait for the element_to_be_clickable().

As an example, to send a character sequence to the user name field you can use either of the following Locator Strategies:

  • Using ID:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "userNameTrucks"))).send_keys("SrinivasVenkataram")
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#userNameTrucks"))).send_keys("SrinivasVenkataram")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='userNameTrucks']"))).send_keys("SrinivasVenkataram")
    
  • Note : You have to add the following imports:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

References

You can find a detailed discussion on ElementNotInteractableException in:

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Debanjan for the response will try this and keep you posted. Just a query Using XPath is good option to identify the elements because in future if the webpage( HTML code) is updated then chances of our code failing will be more right ?

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.