I'm seeing a strange result, when I put the following in my JUnit code:
selenium.click("link=Test Link");
It works when I'm testing in Firefox but throws an error saying it can't find the link when I test in IE.
Is this a limitation with IE? That seems like a severe selenium bug, I'm banking I'm missing something... ;)
I guess you have the required setUp method for starting the test in IE which is;
public void setUp() throws Exception{
setUp("http://www.google.com", "*iexplore");
}
public void test01 throws Exception{
selenium.open("/");
//I'd just wait for page to load before clicking anything
// that might be a reason...
selenium.waitForPageToLoad("20000");
selenium.click("link=test link");
}
I hope that fixes it...
Do you have any frames on the page? In my experience different browsers can show slight differences in their tolerance for allowing Selenium to find elements if you do not explicitly drill down (or up!) to the specific frame containing the element in question.
Related
I have a scenario where I have to hover over a menu link and click on the drop down sub menus. The code that I'm using is below:
public void changeLanguageTest() throws InterruptedException
{
WebElement LanguageMenu = driver.findElement(By.cssSelector(".change-language>button"));
action.moveToElement(LanguageMenu);
WebElement mongolianLang = driver.findElement(By.cssSelector(".change-language>ol>li:nth-child(3)>a"));
action.moveToElement(mongolianLang).click().build().perform();
Thread.sleep(3000L);
}
But when I run this code, It fails with an error message :-
org.openqa.selenium.UnsupportedCommandException: POST
/session/3077f893-d9ab-487d-b09f-c5bcd135ea31/moveto did not match a
known command
I tried below mentioned code too but no success and same error occurred.
BaseClass.action.moveToElement(LanguageMenu).moveToElement(mongolianLang).click().build().perform();
I'm using webdriver v2.53 and running it on FF v47.0.1.
As a bug logged here geckodriver does not yet implement actions. The actions we will implement are those being defined right now in the W3C WebDriver standard and not those of Selenium.
Selenium has said they will provide a Selenium-to-W3C-WebDriver shim for actions, but this may take some time to produce after we have made our implementation. Implementation in geckodriver/Marionette has not yet started.
As mentioned here from v0.12.0 of geckodriver, Implemented routing for new actions API, but it too is not yet fully implemented in Marionette
You should upgrade your geckodriver.
I have integrated Sikuli with my Selenium project. For the sake of learning, I have used simple gmail login application to automate it using Sikuli. Well, I am able to execute script. Now let's say, I'm typing something in my Username field. And sometimes, the mouse is not hovered to the username field. So my test scripts failed. And it is intermittent behavior.
public static void main(String[] args) throws Exception {
Screen screen = new Screen();
Pattern pattern1 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\UserName.PNG");
Pattern pattern2 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\Password.PNG");
Pattern pattern3 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SignIn.PNG");
Pattern pattern4 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\Next.PNG");
Pattern pattern5 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SignedIn.PNG");
Pattern pattern6 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SentMail.PNG");
Pattern pattern7 = new Pattern("E:\\Projects\\Java\\Demo\\Images\\SentMessage.PNG");
System.setProperty("webdriver.chrome.driver","E:\\Projects\\Java\\Demo\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
driver.navigate().to("https://www.gmail.com");
driver.manage().window().maximize();
screen.type(pattern1,"email id");
screen.click(pattern4);
screen.type(pattern2,"password");
screen.click(pattern5);
screen.click(pattern3);
screen.wait(pattern6,20);
screen.click(pattern6);
screen.wait(pattern7,5);
screen.click(pattern7);
}
Does anyone have an idea why this happens?
First of all, share your code.
Usually, intermittent behavior like you describe is caused by timeouts. Meaning that you are looking for an element that is not there yet or has not yet become stable.
A practical example in your scenario can be trying to detect the username field before the page has fully loaded. It will be useful to know how you have used both tools. What you used for navigation and what for elements identification?
Saying that, the quickest way to try and solve this problem is to put few seconds delay before you start searching for username element. See if that helps you.
EDIT
Now when you have posted your code, have a look at these two lines:
driver.manage().window().maximize();
screen.type(pattern1,"email id");
Here, you maximize the browser window and immediately try to find and type into the element described by pattern1. This is likely to be a problem since your driver instance does not wait for the window to become maximized and the next command will start executing immediately. You should allow some time to ensure that the window has finished resizing. just add a short sleep between these lines and see if that helps.
As it happens intermittently and occurs for the very first action in a newly drawn screen this looks like a timing problem.
The Sikuli solution here is to wait until your input field is available before you use it.
The statement to use is:
wait(pattern1[, seconds])
Insert just before:
screen.type(pattern1,"email id");
Reference:
http://doc.sikuli.org/region.html#Region.wait
I have been trying to write a Selenium project to test against a Salesforce app. After much trial and numerous error messages popping up intermittently in various places, I think I narrowed it down to something on Saleforces' end. It appears to get hung up after the 10th record. When I tested the next 10 it got hung up at the same spot. I am thinking this may be some sort of DoS defense used by Salesforce. I was also thinking that after every 9 records I would "recycle" the web driver. Is this possible, as it is a static object (following the code by a guru on Pluralsite).
static OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
public static IWebDriver driver = new ChromeDriver(#"C:\mydocs\", options);
But if I close the browser using
driver.Close();
or
driver.Quite();
the entire static class gets hosed. I do not use static classes much. Is there a way to "clear" the class?
Why not just write a method that resets it to a new instance?
public static void resetDriver() {
driver.quit();
driver = new ChromeDriver(#"C:\mydocs\", options);
}
I'm pretty new to Thucydides / JBehave, but haven't found any solutions posted to this one. This is the first time I've used Thucydides / JBehave, but have used Selenium before.
I have my .story file. The .story file lists 5 scenario's.
Each scenario is implemented in it's own POJO java class.
e.g
public class ManagerBypassLoginSteps
{
#Steps
ManagerSteps managerSteps;
#Given("the manager is not logged in")
public void mangerLogsIn()
{
managerSteps.start();
}
#When("the manager goes to a different page")
public void managerToDashboardPage()
{
managerSteps.goesToDashboardPage();
}
#Then("they should see the login page")
public void managerShouldSeeLoginPage()
{
managerSteps.verifyOnLoginPage();
managerSteps.close();
}
}
The ManagerSteps class extends net.thucydides.core.steps.ScenarioSteps, but is otherwise just a POJO. The ManagerSteps calls the page objects - all very normal stuff and as per the examples.
In the scenario above, the test fails as the code displays an error message instead of returning the user to the log in page - that's fine, the security code doesn't meet the specified requirements (yet) But, after the assert inside the ManagerSteps class fails, the test appears to stop. This means I have a browser instance just sitting there until I close it. When run as a series of tests, this means a broswer in the Selenium grid is now tied up.
I need a way to detect a test failure, to call to the page object to close / quit.
I can't find the equivalent of a #Before or #After that will always run, I could find it I could use the #After to close the page object's webDriver.
I am not using Thucydides to manage the WebDriver lifecycle as I couldn't find any examples of this that did not use the ThucydidesRunner.class.
Do I have to use the ThucydidesRunner.class ? My impression from the Thucydides manual for integrating with JBehave (http://thucydides.info/docs/thucydides/_writing_acceptance_tests_with_jbehave.html) didn't suggest it was required.
How does everyone else handle test failures in this situation ?
The real problem I had was closing the browser, after a test failure.
The best way to manage the WebDriver appear to be to use the Thucydides #ManagedDriver annotation to handle the lifecyle.
I ended up using a very simple JUnit runner like so
public class UserLogin extends ThucydidesJUnitStory
{
#Managed
public WebDriver webdriver;
#ManagedPages(defaultUrl = "http://localhost:8080/dc-bus-main-web")
public Pages pages;
}
When this is started, it maps to the user_login.story file, through JBehave's naming convention, then starts normally.
Though have been able to use simple CSS (just including id, name) but "nth-type" gives up.
Here is the test method -
public static String GetTextByCSSSelector(IWebDriver webDriver, String cssLocator)
{
return webDriver.FindElement(By.CssSelector(cssLocator)).Text;
}
and this is the method call -
GetTextByCSSSelector(_webDriver, "css=div#filelist div:nth-child(1)");
and this is the exception -
OpenQA.Selenium.WebDriverException : An invalid or illegal string was specified
I used the locator mentioned above in Selenium IDE and it does highlight the element.
Any guess?
#
On a different note, did you support Selenium Proposal on area51 -
http://area51.stackexchange.com/proposals/4693/selenium
You just need to click Commit button to support site, while having logged using your Google/Yahoo account.
This proposal is backed by SeleniumHQ and we need more users to commit to it to make it see day of light.
#
Try div:first-child.
If that works it would imply that you only have CSS2 ability, not CSS3 ability.
Remove css= from selector, and enjoy :)