Highlighted
Trusted Contributor.
Trusted Contributor.
1602 views

UFT cannot click element even when xpath is correct ?

I have a webpage where UFT cannot find an element, even when the element is visible and the xpath for the element is correct (checked in chrome developer tools).

Let me explain a bit about the application. It is a book reader which is inside an iframe. It has a navigation bar with two buttons, one for previous page and the other for next page. Clicking on the next/previous page button loads the correct page, without navigating to a different url.

I made two vbscript functions, one to click the next page and the other to click the previous page. I run the two functions in either order (next - previous or previous - next). The xpath for both buttons is correct. But, only the function which runs first completes successfully. The second function always fails because it cannot find the element, even though I can find it and my locator is correct.

Any clues as to why this might be happening and how I can fix it ?

Here is all I can share for the navigation bar.

<div class="nav-bar">
<div class="previous-page">
<div title="Page2">
<svg>
<path></path><!---The previous page button-->
</svg>
<span class="pages">The page 2</span>
</div>
</div>

<div class="current-page">
<span>Page 3</span><!---This is the currently opened page-->
</div>

<div class="next-page">
<div title="Page4">
<span class="pages">The Page 4</span>
<svg>
<path></path><!---The next page button-->
</svg>
</div>
</div>
</div>

Here is the vbscript code snippet:

Function clickNextPage
With Browser("title:=esmart").Page("magic-e-reader").Sync
If .WebElement("xpath:=//div[@class='nav-bar']//div[@class='next-page']//div[@title]").Exist(5) Then
.WebElement("xpath:=//div[@class='nav-bar']//div[@class='next-page']//div[@title]").Click
print "Navigated to next page !"
Else
print "ERROR : Failed to navigate to next page !"
End If
End With
End Function

Labels (2)
Tags (1)
0 Likes
4 Replies
Highlighted
Super Contributor.
Super Contributor.

Re: UFT cannot click element even when xpath is correct ?

The code seems fine. Would it be possible that the page structure changed after one execution of the navigation? Have you tried to highlight the target object from UFT after one navigation (You can create a new WebElement object with xpath as description inside object repository) ?

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: UFT cannot click element even when xpath is correct ?

I am not sure, but I don't think that the page structure changed after execution of one navigation. The navigation bar is inside an iframe with the same ID. Is there an easy way to find out if the page structure has changed ?

I tried to highlight the element also, by adding a line of code with .Highlight. The automation still fails. If this is of any help, then here is the code generated by record feature of uft.

Browser("esmart").Page("magic-e-reader").Frame("Frame").WebElement("Page1").Click
Browser("esmart").Page("magic-e-reader").Frame("Frame_2").WebElement("Page2").Click
Browser("esmart").Page("magic-e-reader").Frame("Frame_3").WebElement("Page3").Click
Browser("esmart").Page("magic-e-reader").Frame("Frame_4").WebElement("Page4").Click
Browser("esmart").Page("magic-e-reader").Frame("Frame_3").WebElement("Page3").Click
Browser("esmart").Page("magic-e-reader").Frame("Frame_2").WebElement("Page2").Click

I wonder why UFT records the frames as frame, frame_2,3,4 etc. There are no elements such as frame_2 in the dom.

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: UFT cannot click element even when xpath is correct ?

We've seen this sort of trouble, too.

Methods that worked before don't work in a new script (for the same APP).

We found that turning on the "Record" function and going through the "point and clicks" that are what we want to happen, UFT will generate lines in the test script "Action" where we want it.
These lines are similar to but different than the script lines that we wrote to perform the action in the APP.
Those lines work every time we run them after that.

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Re: UFT cannot click element even when xpath is correct ?

I am still unable to fix this. Btw, the iframe with buttons is inside another iframe. I tried doing the things below and was not able to click the buttons inside the innermost iframe.

Browser(blah).Page(blah).Frame("id:=parentFrame")
 .Frame("id:=child").WebElement("the button").Click( )

OR

Browser(blah).Page(blah)
 .Frame("id:=parentFrame").Frame("id:=child").WebElement("the button").Click( )

How do I figure out what the problem is and fix it ?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.