Some One
Some One

Reputation: 55

I can not find the element (input tag) on the page

I'm trying to enter username and password to login to my bank account by VBA. I can find the password Input Tag to enter the password, but cannot find the userform Input Tag at all. I tried the following methods one by one, but none of the Find methods worked and there is no other attributes for this tag which I can look for

Dim Mybrowser As New WebDriver
Set Mybrowser = New WebDriver
Mybrowser.Start "chrome"
Mybrowser.Get "https://tbconline.ge/tbcrd/login?t=false"

Mybrowser.FindElementByName("loginUsername1633281403139").SendKeys ("test")
'or
'Mybrowser.FindElementByClass("fblock100 > .ng-valid").SendKeys ("test")
'or
'Mybrowser.FindElementByCss("css=.fblock100 > .ng-valid").SendKeys ("test")
'or
'Mybrowser.FindElementByXpath("//input[@name='loginUsername1633281403139']").SendKeys ("test")
'or
'Mybrowser.FindElementByName("loginPassword1633282058600")

Am I making a mistake in the code ? or is it true that sometimes we cannot find some elements by find method on a page, although they exist there ? Thanks for your advice.

Upvotes: 1

Views: 196

Answers (2)

Nandan A
Nandan A

Reputation: 2922

The name attribute value loginUsername1633281403139 seems to be dynamic so always use some static attributes to find elements or write reliable xpaths. Please see below different ways to find elements.

UserName:

CSS : input[name*='loginUsername']

xPath#1 : //input[@formcontrolname='username']

xPath#2 : //input[starts-with(@name,'loginUsername')]

xPath#3 : //input[@ng-reflect-name='username']


Password:

CSS : input[name*='loginPassword']

xPath#1 : //input[@formcontrolname='password']

xPath#2 : //input[starts-with(@name,'loginPassword')]

xPath#3 : //input[@ng-reflect-name='password']

I would suggest you to practice with finding locators. Please go through this tutorial it will helps you.

Upvotes: 1

cruisepandey
cruisepandey

Reputation: 29362

The Name or CSS that you've used, looks brittle in nature, Probably generated by backend framework, so on every run they will change, Please use customize and optimize CSS or Xpath from below.

Note that CSS has more preference than XPATH

Please use this css for username

input[formcontrolname='username']

xpath

//input[@formcontrolname='username']

for password field :

css

input[formcontrolname='password']

xpath

//input[@formcontrolname='password']

You can learn CSS from here.

Upvotes: 1

Related Questions