I'm writing some tests for our web application. When I use this XPath inside the Firefox XPath-Checker plugin it just works fine:
//div[contains(#class, "my-class") and #data-custom-attr="id")]
But If use this in selenium code like so:
(new WebDriverWait(driver, MAX_TIMEOUT_FOR_ELEMENT_LOADING_IN_SECONDS)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(#class, \"my-class\") and #data-custom-attr=\"id\")]"));
a timeout exception is throwen.
Why does the xpath query works directly in the browser but not in the selenium test? Is there documentation on what I have to consider?
As side note: if I use the exact path /html/body/div/... etc. it does work. And a css selector pendant to my example above doesn't work either.
It should work, what's the max wait time you given in code.
Related
I'm using Appium/WebDriverIO/MacOS to test a React-Native project (it runs on MacOS). I haven't been able to figure out the correct selector to use to find a UI element.
For a React functional component, what prop will I have to set on it to be able to select it? And how can I select it from the tests itself?
I've tried using WebDriverIO's $ selector, but it hasn't worked, saying the locator strategy is not supported for this session
$ != selector
$ is a short form of findElement , what selector strategy to use depends on what format you use:
example, $('~someaccessibilityid')
https://webdriver.io/docs/selectors/
Note: See what all selectors the underlying driver or server like appium supports and use it. For example winappdriver doesn't support css , so you cannot use css strategy
read this to know all available selector strategy
I have been using CasperJS + PhantomJS to walk through a site, http://example.com. As it does so, tracking calls to http://just_another_tracking_service.com/?with&some¶ms are fired (I have a separate scripts that captures and deals with those calls). These always return a tiny gif, with the correct mime type. The protocol for the gifs is http.
I have been trying to use the same CasperJS script to do the same with SlimerJS - the walking-though-the-site part works very well (much better than PhantomJS in fact). But no calls to http://just_another_tracking_service.com/ are sent. I have tried enabling web security this way, but no joy.
Edit: removed pageSettings from code sample, it didn't make any difference, as this page explained http://docs.slimerjs.org/current/configuration.html
var casper = require("casper")
.create({ waitTimeout: 10000 });
Any ideas what I am doing wrong / what should I be doing? Thanks in advance.
Is there a way to use winston or bunyan with CasperJS ? I couldn't get either to load correctly.
I tried the proxy method described in Can't require Underscore with CasperJS, but that also didn't work.
I am new to Capybara testing and am having a few issues.
I have a scenario I am trying to run, and this is the step implementation:
When /^I select the signin link$/ do
click_link 'Sign in'
end
I have tried to access this link with xpath, css, and tried the within implementation as well. Capybara cannot seem to find it, and returns a Capybara::ElementNotFound exception in all cases.
When I load the webpage without JavaScript, the link is not visible, and I'm wondering if this is why Capybara cannot find it. I found a trigger method, but am unsure how it works. Does anyone have a working example of trigger, or any other ideas for what I should do?
Are you using the selenium webdriver to run this test? It sounds like you are trying to run a scenario that requires javascript to see certain elements, without using a driver that supports javascript.
In your .feature file all you have to do is add this line before the scenario:
#javascript
Scenario: My Scenario
When blah blah blah
...
The #javascript tag tells capybara to use selenium-webdriver to run the test. It'll fire up firefox and go through the test - allowing all javascript functionality to work. This slows tests down considerably so only use it when absolutely necessary to test ajax-y and javascript-y behavior.
If that still doesn't work you can use this step:
Then show me the page
When I select the signin link
Which will open the page up for you in a new browser in that page's current state for your inspecting pleasure.
From reading the Selenium documentation, I can see that there is a "newPageLoaded" flag that gets set when you perform a page-loading action. I'm trying to find out if there's a way to get at the value of that flag as the page is loading.
How to do this using the Ruby client would be great. : )
Can you try something like this?
selenium.getEval("selenium.browserbot.isNewPageLoaded()");