last day (14 days later) » 

11:44 AM
0
A: Locating WebElements using XPATH (NoSuchElementException)

legrassYour expression works on Firefox, but on webkit-based browser (e.g., chrome) the rendered DOM is a bit different. Maybe it depends on localization (google.co.uk for me). If I force on google.com the image logo for me is: /html/body/div/div[5]/span/center/div[1]/img on firefox 37 and /html/body...

 
How is the rendered DOM different? Your xpath expression isn't working for me.
 
Can you identify what browser is using your code? I can post screenshots that show that your expression works in firefox 37 but not in chrome 42. Maybe it depends on localization (google.co.uk for me). If I force on google.com the image logo for me is: /html/body/div/div[5]/span/center/div[1]/img on firefox and /html/body/div/div[6]/span/center/div[1]/img on Chome.
 
It is using htmlUnit. My problem doesn't have explicitly something to do with the google homepage or the localization. I get the same error (NoSuchElementException) when using xpath on other websites.
 
ok, htmlunit is tricky. Are you saying that any expression on any site does not work? For instance if you run /html will it work?
also, try to test a website less difficult for htmlunit (it struggles with javascript). Something more static, like wikipedia, just to give a try
 
When I try /html on google homepage, I get a WebDriverException: Cannot determine size of element.
 
11:49 AM
ok this is different, it seems the node is found. In my experience with webdriver and htmlunit, on heavily scripted sites like google, the dom that htmlunit is producing is different from what real browsers render, because htmlunit uses a different javascript engine. I have solved the problem by looking at the source that htmlunit produces, calling the method:

window.getEnclosedPage().getWebResponse().getContentAsString();

This is the real dom as rendered by htmlunit, and your expression need to match on this dom
 
Hi Guys
 
12:26 PM
Oh thats a good hint. So maybe my problem is solved when I use a different WebDriver like FirefoxDriver?
What is the window object?
 
12:40 PM
yes if you can switch to FirefoxDriver you will be fine not just for tihs problem but for many others.
HTMLUnit has issues also on recent Jquery and CSS
window is returned by htmlunit, but you are right, is not exposed via Webdriver API. my suggestion is really to go to firefoxdriver (or chromedriver) or even phantomJS + ghostdriver if you need a headless browser
 
but i cannot really set up any other browser than the standard htmlUnit
I have added the code snippet in the arquillian.xml and added the profiles in the pom.xml
but I am getting java.lang.RuntimeException: Unable to instantiate Drone via org.openqa.selenium.firefox.FirefoxDriver(Capabilities): java.lang.NoClassDefFoundError: com.google.common.base.Optional
 
you need to also add the dependecy probably
instead of
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.11</version>
</dependency>
</dependencies>
those relative to firefoxdriver
 
I dont understand. Do I need to delete those two dependencies? What do I have to add?
I think it is not stated in the guide what dependencies are needed to run the FirefoxDriver
 
12:58 PM
well it says that "If you’ve set up Arquillian previously, you should already have the JUnit and Arquillian JUnit integration dependencies under the dependencies element."
without dependencies how it can find the classes?
however, I dont' know anyhting of this framework
but I'm falry sure that you need to google how to set up it with firefox
 
I have those two you just posted in my pom. Cant figure out what to add for the FirefoxDriver
 
1:26 PM
sorry can't help... I just see in the guide:
Next you need to setup arquillian.xml in order to change the Arquillian settings for browser selection. Add the following to the arquillian.xml:
but you did that
sorry can't help more
 
Ok, anyway, thanks a lot for your help legrass :)
 
btw the class missing in the error
is from GUAVA
try to see if it is in your dependencie
and if is the correct omne
one
 
What is GUAVA?
 
google library for Java
com.google.common.base.Optional
is missing
or there is a double dependency in maven and java cannot resolve
it
 
You are right! I deleted one dependency and now the FirefoxDriver is working! :)
 
1:58 PM
great! Would you be so kind to accept my answer on stackoverflow (this will give me some reputation)
 

last day (14 days later) »