1
votes

I'm trying to run the line of code below in my script, but I get an error saying that more than one object with these properties was found on the page.

Browser("browser").Page("page").WebElement("css:=.normalDayOfMonth").Click

So, I tried adding an index, as shown below:

Browser("browser").Page("page").WebElement("css:=.normalDayOfMonth", "index:=0").Click

But now it's not detecting any object at all. Could anyone help me out with this? Thanks!


Edit: For anyone else who comes across this, it turned out I was using QTP10 and as Motti pointed out below, CSS and Xpath support was only added in QTP11.

1
The following works for me on IE8 Browser("Google").Page("Google").WebElement("css:=.gbts", "index:=0").Highlight. Please see if it works for you, if not try to post some more information. - Motti
I'm getting a general run error for that? I was using the regular Google.com URL - khalid13
I have QTP11 with patch QTPWEB_00090 installed, perhaps you should try installing this patch (if you don't already have it). - Motti
I have QTP10, and I don't think it has the highlight function? I tried using the click function, but it reproduced the same problem. I'm on a corporate computer, so unfortunately I can't add any patches. :( Is there anything obvious I could be overlooking? - khalid13
I've updated my answer with a workaround for QTP10, please take a look. - Motti

1 Answers

1
votes

The support for using CSS and XPath to identify test objects was added in QTP11, in your comments you say that you're using QTP10 which would explain why you're facing problems...

What's probably happening is that QTP is ignoring css as an unrecognizd property so your description matches all elements and then when you add index:=0 it brings one of the invisible elements (e.g HEAD or HTML) which can't be clicked.

If all you're trying to do is match the className you can use QTP's class identification property ("class:=normalDayOfMonth").

BTW the Highlight function is an undocumented function similar to the object repository's highlight functionality and can be very useful in troubleshooting tests.