aspose file tools*
The moose likes Testing and the fly likes programming problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "programming problem" Watch "programming problem" New topic
Author

programming problem

david santana
Greenhorn

Joined: Dec 08, 2011
Posts: 10
Hi, I'd like to ask two question in this thread..
1. why do I keep getting AssertionError with this code? when I tried printing it out to the console, the string is correct.


2. why can't I get the "a" elements using this code? it works fine in the IDE but returns null in Java... is that even possible?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18880
    
    8

(1) You get the AssertionError because the boolean expression passed to the assertTrue() method is false.

(2) Hard to say much more than "Because you did something wrong or made an incorrect assumption". There's no context at all for your question. Would you like to post some details about your question?
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
Definitely could use some more details on #2. From the code snippet, I gather you are using Selenium web driver? If you are able to supply the content you are retrieving in the browser?

From my experience with Selenium webdriver, using the By.xpath failed for me because I either had the xpath expression wrong for the page -or- the page contained frames and webdriver does not seem to work with frames (I wrote some routines to cycle through frames and execute the "By" expression on the frames). I posted the latter on the selenium forums and have not seen any 'fixes' at this point. For the former, I dug deeper into how XPath works.
david santana
Greenhorn

Joined: Dec 08, 2011
Posts: 10
the page I'm testing on no.1 looks like this:

so how come the string "my school is" doesn't match? (for startsWith method)

the page I'm testing on no.2 looks like this:
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
For the first one, if you inspect the portion of the statement "driver.findElement(By.id("address")).getText()" what are you getting? You may have some white space or something at the top. Is there another element on the page with id='address' which you could be getting instead?

On the second one, I think you are making the same mistake I did while starting up with Xpath. 'By.xpath("//div[@id='content2']//a"' does not exist. Looking at your example, it is more something like //div/div/ul/font/li/a (I may be missing a few too at a quick glance!) If you want it to find the ''a'' element you'll need to give some instructions to have it go deeper in the chain (you can do some wild carding).

Depending on whose page this is, I will also suggest you look into using an approach like //div[contains(@id,"text")] as opposed to a straight equals that way if the id is augmented or rendered differently on another browser like with spaces it will still work. Also helps if you get into some complex tags you can just specify enough to match what you are looking for.

I used this site as a basis to build an XPathTest of my own to explore XPath syntax deeper. If you have not seen it, review the xpath tutorial at w3schools. I have used this almost exclusively as my reference for what can be done.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: programming problem