• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

programming problem

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 28174
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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?
 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic