Selenium script too slow with new FirefoxDriver() - java

I doing automation on a particular website(say xyz.com). When I open the URL manually, it lands me onto a login page as expected and I am able to login there as well.
However, when I am automating the scenario by creating new instance of Firefox using new FirefoxDriver(), login page opens quickly but; when I click on login button it takes almost 2 minutes to navigate to a homepage.
I tried using a new profile but it didnt help.
I am using Selenium 2.44.0 on MAC with Java(Eclipse).
Please help.

I had the same problem with Selenium. What I ended up doing was making the webdriver wait till the page title changes(to homepage) using Expected Conditions.
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.titleContains(": My Expected Page title"));
I would suggest you to have a look here:
driver.wait() throws IllegalMonitorStateException
Wait for page load in Selenium

Related

How to access newly opened page in same tab using selenium webdriver

I am unable to access the newly opened page after submitting a form in same tab (not in new tab). I am a newbie in selenium driver, please help me.
In-fact, I accessed first page and filled form successfully, and then I clicked a submit button and proceed to next page, opened in same tab. But then I failed to access that newly opened page.
I also use 10 sec explicit wait to manage form submission and new page opening time but doesn't working. I didn't use WindowHandles() because I am not comfortable to use that. Will Windowhandles() work ?
Only one way I am able to access new page by using separately navigate().to() method after clicking submit button. But is this good approach to get control at new page rather than automating control to new page by some other way ?
I used following explicit wait and then accessed a button at newly page, but doesn't working:
WebDriverWait WaitVar = new WebDriverWait (driver, 10);
WaitVar.until(ExpectedConditions.visibilityOfElementLocated(By.id("BTNCustomQuestionFinalStep")));
driver.findElement(By.id("BTNCustomQuestionFinalStep")).click();
Without using explicit wait I got following error:
no such element: Unable to locate element
After using explicit wait I got following error:
Expected condition failed: waiting for visibility of element located by By.id: BTNCustomQuestionFinalStep (tried for 10 second(s) with 500 milliseconds interval)

How to solve the stale element reference exception in Selenium on clicking on button and verifying the title of next page?

The below test is written using Selenium-
I have a test case where I click on a "next>>" button and the application performs some calculation on server and renders to a new page, but after clicking the "next>>" button sometimes it takes 1-2 minutes to open the next page.
In this test case I am verifying the title of next page to confirm that the next page actually opened and after that I perform further actions to this next page.
But the problem I am facing is when I click on "next>>" button and server take some time, the code to verify the title gives stale Element Reference Exception. If I remove the verify Title code block it perform further actions without any error.
Please suggest some solution to this problem.
I'm not sure this will help as you didn't share the whole code
but you can make selenium wait until the page is loaded before assertion
Try below code
WebDriverWait wait = new WebDriverWait(driver, 180);
wait.until(ExpectedConditions.visibilityOf(// element in the page to be
displayed after you press next);
By using this before the assertion Selenium will not make the assertion until the page is loaded

How to know web page has been loaded completely using phantomjsdriver in java

Here, I am getting page content using phantomjsdriver. I am able to get the complete content of static web pages.
But,I am not able to get complete content of web pages having ajax calls(dynamic web-pages). When I try the below code
I am able to get the content of dynamic web-pages. But I can't predict the loading time of page. So,I am looking for
functions that tells page as been loaded completely.
WebDriver driver = new PhantomJSDriver(caps);
driver.get("http://www.blackwoods.com.au/search/flat-cut-off-wheels-metal-flexovit/302022874");
thread.sleep(10000);
System.out.println(driver.getPageSource());
driver.quit();
Here, I want to use function other then thread.sleep(10000);.
Even I tried with below code. But didn't get the complete content
WebDriver driver = new PhantomJSDriver(caps);
driver.get("http://www.blackwoods.com.au/search/flat-cut-off-wheels-metal- flexovit/302022874");
WebDriverWait wait = new WebDriverWait(driver,15);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ProductsPane")));
System.out.println(driver.getPageSource());
driver.quit();
Have a look at Web Testing Box and especially look at WaitTool which allows you to easily wait for elements to appear.
The tool for you is waitForJavaScriptCondition() which allows you to run a piece of JavaScript (in the context of the page under test).
You will then have to look at the framework which is used. If the page uses jQuery, for example, you can use $.active != 0 as condition (see "How do I know if jQuery has an Ajax request pending?").

Trouble with using Selenium Webriver features

i didn`t find any useful info about my problem. sorry if i repeat.
for example i want to click at the main page of http://www.bbc.com/ in the bottom of site link "Mobile site". in casual i do smth like this, to click on my button:
driver.getMouse(driver.findElement(By.Id("blq-footer-mobile"))).click();
but now i need to simulate the activity of user.
1. i need to scroll the page to bottom
2. need to move the cursor on link
3. click it
i realy tried all what i found in the internet, but everything wrong.
WebDriver simulates user interactions with web applications using native browser APIs. So as long as you are using pure WebDriver API, you are simulating natural user. You don't need to explicitly scroll, WebDriver would do that for you. If it's not scrolling then it is a bug and please report it accordingly. As for your question, here is the code that works.
WebDriver driver = new FirefoxDriver();
driver.get("http://www.bbc.com/");
WebElement element = driver.findElement(By.id("blq-footer-mobile"));
element.click();
The Mobile site link in the above website will just take u to UK website of BBC..
which means, a click on Mobile site link in http://www.bbc.com/ will actually lead you to http://www.bbc.co.uk/, where in the page remains same with just the URL changed..
if you really want to experiment on Mobile site link, use this URL : http://www.bbc.co.uk/
you can try the following code :
WebDriver driver = new FirefoxDriver();
driver.get("http://www.bbc.co.uk/");
new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.id("blq-footer-mobile"))).click();
this will wait for elements visibility and click on it,and this will take you to actual mobile site of BBC..

WebDriver HTMLUnit issues with Ajax

I want to test a site using selenium webdriver (java), but that site contains ajax and HTMLUnit does not see the ajax content.
Is there a workaround?
Example:
WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
//login into your account
this.login(driver);
//click on edit Profile Link into an ajax-loaded tab
driver.findElement(By.id("editProfile")).click();
//Result: org.openqa.selenium.NoSuchElementException
use Wait condition before interaction with element with must appear after ajax response.
WebDriverWait wait = new WebDriverWait(webDriver, 5);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_to_element")));
this makes webDriver to wait for your element during 5 secs. This question was asked earlier.

Categories

Resources