danwagnerco / selenium-vba

Automatically exported from code.google.com/p/selenium-vba
1 stars 0 forks source link

Need Help #83

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Operating system and version (32/64bit) : Windows 7, 32 Bit
.Net Framework version :3.5
Office name and version(32/64bit) : Office 2010 , 32bit
Browser name and version :IE 8
SeleniumWrapper version : 1.0.19

I am working on Testing Project wherein I required to 
1. To open intranet site 
2. Enter UserName and Password in popup window.
3. Enter value in field name "tfPRNum" and press go button. 

Now the issue is step 1 and 2 workfine however getting an error in step 3 
that element not found.

Below is the code I have written.

Public Sub untitled2()
  Dim driver As New SeleniumWrapper.WebDriver

  driver.Start "ie", "http://Site Link"
  driver.Open "/"

  driver.waitForPopUp "Login", "5000"
  driver.findElementByName("tfUserName").Clear
  driver.findElementByName("tfUserName").SendKeys "USERNAME"
  driver.findElementByName("tfPassword").Clear
  driver.findElementByName("tfPassword").SendKeys "PASSWORD"
  driver.findElementById("btLoginId").Click

 driver.setImplicitWait 5000

'driver.findElementByXPath("//input[@name='tfPRNum' .plain > tbody:nth-child(1) 
> tr:nth-child(1) > td:nth-child(1) > input:nth-child(1)").Clear

  driver.findElementByName("tfPRNum").Clear
  driver.findElementByName("tfPRNum").SendKeys "15014501"

End Sub

Also, try to locate unique identifire of Object in firefox.  Not sure if 
correct.

.plain > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(1) > 
input:nth-child(1)

I have attached the screen shot of the window and HTML code for reference.

I am new to selenium VBA.  Really appriciate any help out here.

Thanks in advance.

Regards
Rohit 

Original issue reported on code.google.com by rohitkbh...@gmail.com on 5 Aug 2014 at 1:42

GoogleCodeExporter commented 9 years ago
It looks like your HTML and screenshot are missing. Can you add them again?
And which line of your script is throwing the error at step 3?

Original comment by florentbr on 5 Aug 2014 at 6:09

GoogleCodeExporter commented 9 years ago
Please find the attached screenshot and HTML for your reference.

Just to update, this form opens up in popup window.  Also I have tried below 
line of code to find element 'tfPRNum' but fail.

driver.findElementByXPath("//html/body/center/form[1]/table[2]/tbody/tr/td[1]/in
put[1]").Clear

driver.findElementByXPath("//html/body/center/form[1]/table[2]/tbody/tr/td[1]/in
put[1]").SendKeys "1111111"

driver.findElementByXPath("//*[@name='tfPRNum']").SendKeys "111111"

Thanks & Regards
Rohit

Original comment by rohitkbh...@gmail.com on 6 Aug 2014 at 10:41

Attachments:

GoogleCodeExporter commented 9 years ago
The command driver.findElementByName("tfPRNum") is correct, which means that 
the current window doesn't contain the element at the time the command is 
executed.

So either the current window is not the expected one and in this case you need 
to switch to it:
driver.switchToWindow "page name"
To get the current page name: driver.Title

Or the page is not loaded within 5 seconds and therefore you need to adjust the 
timeout :
driver.findElementByName("tfPRNum", 15000) 'Throws an error is the element is 
not found within 15sec
or 
driver.setImplicitWait 15000  'Throws an error an element is not found within 
15sec
driver.findElementByName("tfPRNum")

Original comment by florentbr on 6 Aug 2014 at 12:09

GoogleCodeExporter commented 9 years ago
Thanks Florent for your help.

Now getting an error while Switching the window. I got the title using 
driver.title and using the same in driver.switchtoWindow.   below is the code

Also tried, driver.selectWindow ("Page Name") which seems to be working fine.

Sub Testing()
  Dim driver As New SeleniumWrapper.WebDriver
  driver.Start "ie", "http://trackwise.health.ge.com/PRD1TWSTeamAccess/"
  driver.Open "/"
  driver.setImplicitWait 5000
  driver.waitForPopUp "Login", "5000"
  driver.findElementByName("tfUserName").Clear
  driver.findElementByName("tfUserName").SendKeys "UserName"
  driver.findElementByName("tfPassword").Clear
  driver.findElementByName("tfPassword").SendKeys "Password"
  driver.findElementById("btLoginId").Click
  driver.waitForPageToLoad ("30000")
  'Debug.Print driver.Title
  driver.switchToWindow "Desktop - User: XXXX, PID-XXXXX"
  'driver.selectWindow ("Desktop - User: XXXX, PID-XXXXX")
  driver.findElementByName("tfPRNum", 30000).SendKeys "15014501"

'    
driver.findElementByXPath("//html/body/center/form[1]/table[2]/tbody/tr/td[1]/in
put[1]").Clear
'  
driver.findElementByXPath("//html/body/center/form[1]/table[2]/tbody/tr/td[1]/in
put[1]").SendKeys "15014501"
'  driver.findElementByXPath("//input[@name='tfPRNum']").SendKeys "15014501"
End Sub

Original comment by rohitkbh...@gmail.com on 6 Aug 2014 at 1:19

GoogleCodeExporter commented 9 years ago
I have also tried & tested below solution that you provided in one of the 
issue.  below code work sucessfully but fail to find element.   

Handle = driver.WindowHandles
driver.switchToWindow Handle(1)   ' No error
debug.print driver.title    'show correct title of window where element is 
located

''''''''''''
driver.switchtowindow "Page Name"  '''Error if provide absolute page name

It seems the problems is with switching the window.  could you please suggest 
any other way to select window.

Thanks
Rohit Bhatia

Original comment by rohitkbh...@gmail.com on 6 Aug 2014 at 3:09

GoogleCodeExporter commented 9 years ago
You can try this:
driver.waitForPopUp "", "10000"  'May be useless
driver.selectWindow "null"
driver.findElementByName("tfPRNum", 10000).SendKeys "15014501"

and :
driver.waitForPopUp "", "10000"   'May be useless
Dim handles: handles = driver.WindowHandles
driver.switchToWindow handles(0)   'could be another index
driver.findElementByName("tfPRNum", 10000).SendKeys "15014501"

Original comment by florentbr on 6 Aug 2014 at 3:47

GoogleCodeExporter commented 9 years ago
It could also be a frame issue. Another solution would be to open the 
redirection once you are logged in:
driver.findElementById("btLoginId").Click
driver.Open "/redirection"
driver.findElementByName("tfPRNum", 10000).SendKeys "15014501"

Original comment by florentbr on 6 Aug 2014 at 4:01

GoogleCodeExporter commented 9 years ago
Thanks Florent for your continued help & support on this issue.

Tried below

Handle = driver.WindowHandles
driver.selectWindow "null"                '''Move to main window
driver.switchToWindow Handle(1)          'selecting the last window
Debug.Print driver.Title                  '''Printing correct page title
driver.getHtmlSource          ' saved it to notepad file. It seems HTML portion 
is 
                              missing in page source.  therefore not able to locate 
                              any element.  Used Xpath as well but that also got fail

driver.findElementByXPath("//input[@name='tfPRNum']").SendKeys "15014501"
driver.findElementByXPath("//html/body/center/form[1]/table[2]/tbody/tr/td[1]/in
put[1]").SendKeys "15014501"

Original comment by rohitkbh...@gmail.com on 6 Aug 2014 at 4:38

GoogleCodeExporter commented 9 years ago
I assume the missing portion is dynamically created once the page has been 
loaded.
It shouldn't be a problem as the findElementByName is waiting for the element 
when it's used with an implicit timeout.
The only reason I'm thinking of would be the window context, the frame context 
or the proxy configuration if there is any.
You should add a break point just after the log in and then inspect the DOM to 
make sure all the required elements are present.
If some elements are missing, then it means the browser is not properly 
configured (proxy, certificates...)
I was able to locate all the elements with the HTML you provided under IE and 
FF.

Original comment by florentbr on 6 Aug 2014 at 6:37

GoogleCodeExporter commented 9 years ago
Not sure how to get driver.Open "/redirection" .

I have taken the dump of HTML using driver.getHtmlSource in the notepad.  I 
could not able to locate the any of the element or I would  say the whole HTML 
protion was missing whereas the elements were present in the DOM.  Attached is 
screen shot of inspecting element in FireFox.  Also, I have attached HTML dump 
using Selenium and the protion for Missing HTML manually taken from source.

I am not a expert but it seems frame portion get added from diffenet link or 
CSS.

Original comment by rohitkbh...@gmail.com on 7 Aug 2014 at 10:59

Attachments:

GoogleCodeExporter commented 9 years ago
The redirection is just the Url the browser is redirected to once you've 
clicked on the login button.
I had a look at the last attached Html you posted and it has multiple frames 
that need to be addressed with the command switchToFrame to set the proper 
context.
So to address your issue, you can either set the frame context :
  driver.switchToDefaultContent    'May be unnecessary
  driver.switchToFrame 0    'Not sure it's the first frame. You need to inspect the DOM for that
  driver.findElementByName("tfPRNum", 30000).SendKeys "15014501"
Or directly open the frame Url:
  driver.open "/servlet/TeamAccess/Desktop"    'Not sure. You need to get the frame "src" from the DOM for that
  driver.findElementByName("tfPRNum", 30000).SendKeys "15014501"

Anyway, the best way to deal with frames is to use these commands and identify 
the right frame in the DOM:
  driver.switchToFrame "Login"  'frame by name or id
  driver.switchToFrame 0    'frame by index
  driver.switchToDefaultContent     'Reset the frame context

Original comment by florentbr on 7 Aug 2014 at 4:52

GoogleCodeExporter commented 9 years ago
Many Thanks Florent for your help and support. :)

Finally I was able to locate the element into the browser.  Now the issue is 
once I enter the value and click the 'GO' link I am getting message your 
session has expired.  Not sure if I need adjust some settings.

Below is the code:

Sub Testing()
  Dim driver As New SeleniumWrapper.WebDriver
  driver.Start "ie", "LINK"
  driver.Open "/"
  driver.setImplicitWait 5000
  driver.waitForPopUp "Login", "15000"
  driver.findElementByName("tfUserName").Clear
  driver.findElementByName("tfUserName").SendKeys "UID"
  driver.findElementByName("tfPassword").Clear
  driver.findElementByName("tfPassword").SendKeys "PWD"
  driver.findElementById("btLoginId").Click
  driver.waitForPageToLoad ("30000")
  driver.get "/servlet/TeamAccess/Desktop"
  Handle = driver.WindowHandles
  driver.selectWindow "null"
  driver.switchToWindow Handle(1)
  'driver.switchToFrame ("0")
  driver.switchToDefaultContent

   driver.findElementByName("tfPRNum", 2000).SendKeys "xxxxx"
   driver.findElementByLinkText("GO", 2000).Click                ''''SESSION TIMEEOUT
   driver.findElementByLinkText("xxxxx", 2000).Click

     driver.waitForPageToLoad ("30000")
     driver.selectWindow "null"
     driver.switchToWindow Handle(2)
     driver.switchToDefaultContent

    driver.findElementById("CHU Location - Other", 2000).SendKeys "Reg Svcs MV"
End Sub

Original comment by rohitkbh...@gmail.com on 8 Aug 2014 at 12:49

GoogleCodeExporter commented 9 years ago
This message means that the login token is stored in another frame, so you 
can't use the "get" command to directly open the frame.
I can't do much without an access to it.
You should try to identify the right frame or window at each step by using the 
debug mode.

Original comment by florentbr on 21 Aug 2014 at 7:38

GoogleCodeExporter commented 9 years ago
Thanks Florent after some research I was able to locate the issue.  Now its 
seems to be working fine.

Can I request you to please help :

1. How I can get all the Options available in Combobox.
2. Once I select any option in Combo page get refresh. I am getting error 
message in next line of code.  How I can put wait.

    driver.findElementByName("xx", 3000).AsSelect.selectByText "xxxxx"
    driver.findElementByName("xxx", 3000).AsSelect.selectByText "xxxxxxxx"  ' Error

3. In one of the case clicking the weblink open Oracle Webform Applet.  Not 
sure if Selenium can help in testing.  Please help in case you have idea about 
any other technology.

Thanks again in advance.

Original comment by rohitkbh...@gmail.com on 28 Aug 2014 at 4:40

GoogleCodeExporter commented 9 years ago
1, to list all the options:
Set combo = driver.findElementByName("xx", 3000).AsSelect
ForEach option in combo.Options
    Debug.Print option.Text
Next

2, to add a wait:
driver.wait 200 'Waits 200ms

3, Applets automation:
Selenium doesn't support Java applets.
You'll have to use another tool like AutiIt or the Java Robot class.

Original comment by florentbr on 28 Aug 2014 at 7:45

GoogleCodeExporter commented 9 years ago
Hi Florent,

1. How to click "OK" in Alert message.  I have tried below but getting an error.

driver.switchToAlert(2000).Accept  '''error operation has timeout. unable to 
get browser

2.  How to assert if element is present in the file. Its dynamic element need 
to excute code only if element is present.

3. I have tried the solution to list all the options. Getting Error
Set combo = driver.findElementByName("xx", 3000).AsSelect
For Each option in combo.Options
    Debug.Print option.Text
Next

Thanks & Regards
Rohit 

Original comment by rohitkbh...@gmail.com on 3 Sep 2014 at 11:27

GoogleCodeExporter commented 9 years ago
Please ignore the issue 2 & 3.  I was making some mistake in the code.  Can you 
please help with the 1. How to click "OK" in Alert message.  I have tried below 
but getting an error.

driver.switchToAlert(2000).Accept  '''error operation has timeout. unable to 
get browser

Original comment by rohitkbh...@gmail.com on 3 Sep 2014 at 3:03

GoogleCodeExporter commented 9 years ago
Hi Florent,

Could you please help in resolving below issues:

1.  I was making some mistake in the code.  Can you please help with the 1. How 
to click "OK" in Alert message.  I have tried below but getting an error.

driver.switchToAlert(2000).Accept  '''error operation has timeout. unable to 
get browser

2. Iselementpresent is not working tried below 

driver.Wait 2000
If driver.isElementPresent(By.findElementByName("xxx")) Then   'error Object 
Required
       driver.findElementByName("xxx", 2000).AsSelect.selectByText "Updated Data"
End If

driver.Wait 2000
    If driver.isElementPresent("xxx") Then
       driver.findElementByName("xxx", 2000).AsSelect.selectByText "Updated Data"
    End If

Thanks & Regards
Rohit Bhatia

Not able to locate using below but no error

driver.Wait 2000
If driver.isElementPresent("Name=xxx") Then
       driver.findElementByName("xxx", 2000).AsSelect.selectByText "Updated Data"
    End If

Original comment by rohitkbh...@gmail.com on 4 Sep 2014 at 10:06

GoogleCodeExporter commented 9 years ago
Below is working fine:

driver.findElementByName("xxx", 2000).AsSelect.selectByText "Updated Data"

however if try to check if element ispresent then its returning false

driver.Wait 2000
If driver.isElementPresent("Name=xxx") Then
       driver.findElementByName("xxx", 2000).AsSelect.selectByText "Updated Data"
    End If

Original comment by rohitkbh...@gmail.com on 4 Sep 2014 at 4:57

GoogleCodeExporter commented 9 years ago

Original comment by florentbr on 8 Sep 2014 at 5:40

GoogleCodeExporter commented 9 years ago
Hi Florent,

1. How to click "OK" in Alert/Prompt message.  I have tried below but getting 
an error.

driver.switchToAlert(2000).Accept  '''error operation has timeout. unable to 
get browser

2. How to use wait with "driver.isElementPresent("Name=xxx")".  Below is 
working fine
driver.findElementByName("xxx", 2000).AsSelect.selectByText "Updated Data"
but getting error with iselementpresent.

Thanks & Regards
Rohit Bhatia

Original comment by rohitkbh...@gmail.com on 15 Sep 2014 at 8:33

GoogleCodeExporter commented 9 years ago
1. To handle an alert :

Dim wd As New Webdriver
wd.Start "ie", "http://www.google.com"
wd.Open "/"
wd.executeScript "setTimeout(function(){window.alert('')},0);"  'To simulate an 
alert
wd.switchToAlert(5000).Accept

2. to use isElementPresent :
Dim wd As New Webdriver, By as new By
wd.Start "ie", "http://www.google.com"
wd.Open "/"
if wd.isElementPresent(By.Name("xxx")) Then
  Debug.Print "found"
Else
  Debug.Print "no found"
End If

Or with the new option to silent the exception (since v1.0.20).
This example returns Nothing if the element is not found within 2sec, or the 
element itself as soon as it is found:

Set we = wd.findElementByName("xxx", 2000, Raise:=False)  
If we is Nothing Then
  Debug.Print "no found"
Else
  we.click
End If

Or with the selenium 1 command:
If wd.isElementPresent("name=xxx") Then
If wd.isElementPresent("id=xxx") Then
If wd.isElementPresent("css=xxx") Then
If wd.isElementPresent("xpath=xxx") Then

Original comment by florentbr on 18 Sep 2014 at 7:15