sagarpabba / selenium-vba

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

"iselementpresent" is not working as expected with webwrapper 1.0.18.0 #71

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Operating system and version (32/64bit) :Windows 7 Enterprise, 32 bit
.Net Framework version : 4 
Office name and version(32/64bit) :Office 2010
Browser name and version : Firefox 26
SeleniumWrapper version : 1.0.18.0

Issue:
I had the following code, which was working fine in version 1.0.16.0. I am 
using this to see if element is present on the page or not. 

if(driver.isElementPresent("test_xpath")) then
 //Some action
Else
 // Some Action
End if

However, currently with version 1.0.18.0, in above code system always execute 
else condition even if element is present on the screen.

Original issue reported on code.google.com by mohitmon...@gmail.com on 10 Jun 2014 at 7:32

GoogleCodeExporter commented 9 years ago
I successfully ran this test:
Set wd = CreateObject("SeleniumWrapper.WebDriver")
wd.start "firefox", "http://www.google.com"
wd.open "/"
WScript.Echo wd.isElementPresent("id=gbqfq")
WScript.Echo wd.isElementPresent("css=#gbqfq")
WScript.Echo wd.isElementPresent("xpath=//input[@id='gbqfq']")

It could be a timing issue as as the 1.0.18.0 has been improved, or maybe the 
element you are targeting is now loaded asynchronously. Make sure the element 
is present at the time the command is executed by adding a delay or by waiting 
for a similar element before checking the presence.
If you are convinced it's a regression, please provide a full failing example 
on a public website so i can debug it.
Thanks.  

Original comment by florentbr on 10 Jun 2014 at 8:40

GoogleCodeExporter commented 9 years ago
Hi florent,

Please try the following code, If we restart the browser the google search box 
is not found by "iselementpresent". We get the following output:

Element found in run 1
element not found in run 2

Sub google()
    Dim driver As New SeleniumWrapper.WebDriver

driver.Start "firefox", "http://www.google.com"
driver.get "/"

If driver.isElementPresent("//*[@id='gs_tti0']") Then
    Debug.Print ("Element found in run 1")
Else
    Debug.Print ("element not found in run 1")
End If

driver.stop

driver.Start "firefox", "http://www.google.com"
driver.get "/"

If driver.isElementPresent("//*[@id='gs_tti0']") Then
    Debug.Print ("Element found in run 2")
Else
    Debug.Print ("element not found in run 2")
End If

driver.stop

End Sub

Original comment by mohitmon...@gmail.com on 24 Jul 2014 at 8:07

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
'The search box is recognized in second run if we set driver to "New 
SeleniumWrapper.WebDriver" each time we restart the browser. Pls let us know 
whether it is a bug or is meant to be this way?
'PS: the above code from Mohit was working successfully in version 1.0.16.0 but 
stopped working in 1.0.18.0

Sub google()

Dim driver As SeleniumWrapper.WebDriver

For i = 1 To 3

    Set driver = New SeleniumWrapper.WebDriver
    driver.Start "firefox", "http://www.google.com"
    driver.get "/"

    If driver.isElementPresent("//*[@id='gs_tti0']") Then
        Debug.Print ("Element found in run " & i)
    Else
        Debug.Print ("element not found in run " & i)
    End If

    driver.stop

Next i

End Sub

Original comment by rohan.ka...@gmail.com on 24 Jul 2014 at 3:44

GoogleCodeExporter commented 9 years ago
This is a timing issue. The element is not yet created when you are testing the 
presence.
This has nothing to do with whether it's first or second time you run it.
You can add a delay before, or wait for a sibling before testing the element 
presence.

Example using an implicit wait of 2000ms:
Set driver = New SeleniumWrapper.WebDriver
driver.Start "firefox", "http://www.google.com"
driver.setImplicitWait 2000
driver.get "/"
Set element = driver.findElementById("gs_tti0")

Example using an explicit wait of 2000ms:
Set driver = New SeleniumWrapper.WebDriver
driver.Start "firefox", "http://www.google.com"
driver.get "/"
Set element = driver.findElementById("gs_tti0", 2000)

Original comment by florentbr on 28 Jul 2014 at 12:22

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi Florent,

I have added both implicit and explicit wait but still getting the same issue. 
Please see the code below:

Sub google()
Dim driver As New SeleniumWrapper.WebDriver

driver.Start "firefox", "http://www.google.com"
driver.setImplicitWait (3000)

driver.get "/"
Set element = driver.findElementByXPath("//*[@id='gs_tti0']", 3000)
X = element.getAttribute("id")
If driver.isElementPresent("id=" & X) Then
    Debug.Print ("Element found in run 1")
Else
    Debug.Print ("element not found in run 1")
End If

driver.stop

driver.Start "firefox", "http://www.google.com"
driver.get "/"
Set element = driver.findElementByXPath("//*[@id='gs_tti0']", 3000)
X = element.getAttribute("id")
If driver.isElementPresent("id=" & X) Then
    Debug.Print ("Element found in run 2")
Else
    Debug.Print ("element not found in run 2")
End If

driver.stop

End Sub

Original comment by mohitmon...@gmail.com on 30 Jul 2014 at 7:01

GoogleCodeExporter commented 9 years ago

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