2

I am trying to login to a site and I am using FindElementById. In the following code the first part of using SendKeys works well but when trying to use the same technique for the password field, I get an error message which tells me that the element is not interactable

Sub Test()
Dim bot As New WebDriver

With bot
    .AddArgument "--disable-notifications"
    .Start "Chrome", "https://www.excelforum.com/excel-programming-vba-macros/"
    .Get "/"
    
    .FindElementById("navbar_username").SendKeys "username"
    .FindElementById("navbar_password").SendKeys "password"
    '.FindElementByName("vb_login_password").SendKeys "password"
    Stop
End With
End Sub
3
  • A good reproducible example with clear error message and location (+). Would have benefited from using snippet tool to share the html for the relevant node. Commented Dec 12, 2019 at 7:42
  • @QHarr sharing the html is necessary when there is no url but I have attached the url in the code itself so using Inspect would be more useful. Commented Dec 12, 2019 at 8:44
  • 1
    I love having the url present but not everyone may be able to access it. In this case it looks like a pretty accessible one. It was just an observation/suggestion. I was already overjoyed at having a reproducible example hence the upvote. Commented Dec 12, 2019 at 8:46

3 Answers 3

2

You were pretty close. The Password field with id attribute as navbar_password is having the property:

style="display: none;"

So you won't be able to interact with the element.


To send a character sequence both to the User Name and Password field you can use either of the following Locator Strategies:

  • Using FindElementById():

    .FindElementById("navbar_username").SendKeys "username"
    .FindElementById("navbar_password_hint").SendKeys "password"
    
  • Using FindElementByCss():

    .FindElementByCss("input#navbar_username").SendKeys "username"
    .FindElementByCss("input#navbar_password_hint").SendKeys "password"
    
  • Using FindElementByXPath():

    .FindElementByXPath("//input[@id='navbar_username']").SendKeys "username"
    .FindElementByXPath("//input[@id='navbar_password_hint']").SendKeys "password"
    

References

You can find a couple of revelant discussions in:

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

3 Comments

Thanks a lot. It worked when I run the code step by step so I found out that I have to wait a little before sending the data to password field.
How can I make the waiting is restricted to the element when it is available? I mean loop until element is ready to receive the data.
@YasserKhalil Gimme some time, let me look at the VB code, then I will get back to you
1

Try referring this webpage

The page you are trying to access has added a web element over another web element. i.e web element of id navbar_password_hint over web element of id navbar_password. Try referring above link to solve your problem.

1 Comment

Thanks a lot. It seems only I have to put a waiting line before what you suggested.
1

This happens when the element state is not clickable. You have to use webdriver wait property and make sure that element state is clickable

 WebDriverWait wait= new WebDriverWait(driver, 10);
    WebElement e= wait.until(ExpectedConditions.elementToBeClickable(By.xpath("xpath_of_element")));
    e.click();

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.