i try to find elements in edge or IE and it look like that these two browsers are not working with Xpath, more over, i tried to launce my automation in parallel with cheome, IE, Edge, and in Xpath its not working at all (just in chrome it works) but when i change it to css.. it start working
second thing that i noticed that at the CTRL+F while looking for elements, its not highlighted like in chrome
so is there any way to work with xpath? also, it can be that elements in chrome are not the same in edge or IE with css for example? and if so, how can i run in parallel test with that browsers?
This xpath should work in all browsers:
"//foo[contains(#bar,'xy')]"
"//a[contains(#href,'xy')]"
Related
Description
Because I don't yet have got any answer from mine post:
How to get all stocks from the specified URL in selenium headless mode?
I have to work on workaround to get progress on my work! Instead of trying to force an update on the site to get all stocks viewable (as described in my post) I will go to the end of page and then scroll up to force all stocks to get viewable (works fine when I do it manually).
All this MUST work in selenium headless mode!
Problem
I know how this can be implemented in selenium normal mode (not headless) but I can't get it to work in headless mode.
I think this line works both in normal and headless mode to go to the END of page:
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight);");
The issue I'm struggeling with is how to scroll up or pageup from the end of the page. I guess something like this will work:
WebElement e = driver.findElement(By.xpath("element to be returned like Storskogen"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", e);
I can't fetch the element "e", I can't get it work (NoSuchElementException is thrown). I have copied the xpath or css from Chrome without result though. I'm not even sure this will work in headless mode.
Questions
how to fetch element "Storskogen"?
is "scrollIntoView" scrolling working in headless mode?
how can pageup be implemented and working in headless mode?
how can I verify scrolling in headless mode?
It's okay to not answer every question. I use Java for implemention.
Selenium headless window/display size by default is 800x600.
So if you have a lot on your webpage, then you may end up with horizontal, as well as vertical scroll bars on the headless browser. Therefore, dependent on your webpage, the element you are after may not be drawn, hence you have to scroll up and down for it to appear.
To get the best results of scrolling up and down, you want to maximise your browser window. As you want to operate in headless mode, the actual browser will not be active, thus driver.manage().window().maximize(); is not an option.
Do the following:
Update your browser driver with a specific window size that will ensure no horizontal scroll bars. I have used the following for my BrowserDriverFactory as I test with multiple browsers: driver.manage().window().setSize(new Dimension(1920, 1280)); also you could manage a specific browser driver i.e. chromedriver with options.addArguments("window-size=1920,1080");
Then use JavascriptExecutor, as you mentioned above:
Scroll down - ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight);");
Scroll up - ((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollTop);");
I'm currently working on a node/express.js app for which I'm writing some e2e tests in nightwatch. Today I hit a roadblock while trying to search for an element using the XPath locator strategy. Basically I can search for elements using any of the following:
//div[#data-pino-name='userIdSection']
//input[#name="password"]
//input[#name="username"]
//button[#data-pino-name="submit"]
//a[#data-pino-name="cancel"]
By the way, all of the selectors above work fine using the chrome tools.
However, using the following:
//pre[#data-pino-name="requiredErrorMessage"]
doesn't work at all. I'm surprised since I expected the <pre> tag to be treated the same as any other html tag. However, the test returns a "element was not found" for all elements with the pre tag.
Anyone guidance would be appreciated.
You can follow this approach in writing XPath based on your scenario
//div[#data-pino-name='userIdSection']/pre
//div[#data-pino-name='userIdSection']/pre[#data-pino-name="requiredErrorMessage"]
I would like to understand how Selenium evaluates the page.
I have set of test to check elements on the page. Written with Nunit, Selenium and PhantomJS as Driver.
Page.Visit();
Page.FindElement(By.Id("testid").Text.Should().NotBeNull(); // PASS
Page.FindElement(By.Id("testid").Text.Should().NotBeEmpty(); // does NOT PASS
The test DOES NOT pass if the browser size is set to be very small:
driver.Manage().Window.Size = new Size(10,10);
Based on this test, it is confusing how PhantomJS evaluates the page. I always thought that it checks the DOM but seems like for element TEXT it evaluates based on visibility!
Although this surprised me too when I first discovered it, Selenium will only find elements visible in the viewport of the browser. For this reason, you will want to ensure at the start of your tests that your browser viewport is large enough to accommodate the content of your application.
Typically this can be done by maximizing the browser window. If you are using Windows, triggering the F11 key via Selenium should work.
I am trying to do mouse over an element in IE9 browser. After mouse
hover a toll tip will open. To do this I am using:
selenium.mouseOver("css=a.worldwide");
It works fine, in FF browser. But fails in IE browser. I am using:
Selenium RC 2.18.0. I have also try this by both Xpath and CSS
locator. But it fails.
Can any body please help me how can I resolve this issue?
This may be not answer to your question but may help you.
getAttribute("css=a.worldwide#title")); // getAttribute(locator#attribute name)
This function will return the text available for title attribute for the element specified.
Regards
Using javascript/jQuery I managed to work around the problem:
selenium.eval('selenium.browserbot.getCurrentWindow().jQuery("a.worldwide").trigger("mouseover");')
I'm using python, so you may need to adjust quotes.
I have no idea what jQuery does that selenium doesn't, but this made the problem go away for me on Saucelabs & Selenium 1.
In general, when I want to test the validity of a locator to be used in Selenium, I test it using the Firebug console.
i.e., I write: $$("a#someLink") in the Firebug console and the corresponding link becomes highlighted in Firefox.
However, if I test in Firebug for a locator like:
table#someTable tr:nth-of-type(2) td:nth-of-type(2)
Firebug doesn't show anything... Even though the locator works fine from Selenium...
I guess Selenium uses some 'hacks' for CSS locators, which Firebug does not understand...
Is there any way around it? Would using Xpath locators allow me to test for those kinds of locators?
Thank you very much
Firebug has an extension called FireFinder, which allows you to test xpath or css locators and it shows all the matches on the page. Here's a link.