Selenium HtmlUnit freeze randomly loading a web page - java

im having a problem with HtmlUnitDriver using Selenium.
Im using the Selenium 2.5 version.
The test is so simply and usualy it works correctly but sometimes the driver just stop and wait endlessly for a page to load.
my code is something like this:
initialization...
private WebDriver driver;
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);((HtmlUnitDriver) driver).setJavascriptEnabled(true);
//driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
driver.manage().timeouts().setScriptTimeout(0, TimeUnit.MILLISECONDS);
and then a lot of blocks like this one:
new Actions(driver).moveToElement(driver.findElement(By.linkText("Someting"))).perform();
driver.findElement(By.linkText("something else")).click();
driver.findElement(By.name("something")).sendKeys("8");
driver.findElement(By.xpath("//img[#title='something']")).click();
after each clic() it loads a new page.
I usualy end the whole test correctly and i have try catched all the blocks so the web is not the problem.
The webdriver is ignoring the timeouts(i try a lot of diferent timeouts and the problem persists) and i cant stop the driver from another threads invoquing "quit()" or "close()"
I search everywhere but i cant found a solution.
¿Anyone can help me?
Thanks in advance.

I solve it, i post my solution if anyone have the same problem.
Im pressing esc from other thread (the main is busy waiting...)
((HtmlUnitDriver) test.getDriver()).getKeyboard().pressKey(Keys.ESCAPE);
and then i kill the browser and restart the test
test.getDriver().quit(); restart();//create a new test instance

I've faced this behaviour before.
I would first update to 2.9 and try again
Then, I would check the pages I'm hitting, because if they have frames or iframes they get downloaded too and if you don't control their content anything could happen
Take a look at this link because it might have the solution you're looking for.
Hope this helps.

Related

Selenium IEDriverServer not sending keys when using RemoteWebDriver

So I have a test case set up which works perfectly fine using Testng and running the IEDriverServer locally. But when running the test case using Grid 2 the following command doesn't appear to work:
driver.findElement(By.xpath("(//input[#type='text'])[3]")).sendKeys(logNum);
There are no errors and the output from the node states that it had completed, but no text appears in the edit box. I checked running the test through a debugger and the "logNum" variable does have a value
I can not fathom why its not working
I am using selenium-server-standalone-2.44.0.jar running the Hub and Node on the same machine
I have resolved this by removing
capability.setCapability("nativeEvents", false);
from my initiation of the driver.
I recently came across the same problem. I used JavascriptExecutor to set the value of the element.
public static void useJSSendKeys(String value,WebElement element){
JavascriptExecutor myExecutor = ((JavascriptExecutor) driver);
myExecutor.executeScript("arguments[0].value='"+value+"';", element);
}
good to know that your issue is resolved on making capability.setCapability("nativeEvents", false); but it may create problem when you try to perform native events. so if you not tried, please try performing click before sendkeys. it helps me some times and also providing Thread.sleep(3000) in java also helps me in some situations. please try these if not.
Thank You,
Murali

java selenium - hidden input value

First Stack post, so don't be harsh if I get it wrong.
Im using selenium and java for some automated testing. All was going well until I tried to set the value of a hidden input.
When using 'type' in the Firefox IDE, it works a treat, but when I use the line below, it doesn't play at all. It just fails.
// This line doesnt like to run because its hidden
selenium.type("name=startDate_submit", "2015-09-25");
Can anyone point me in the right direction.
Many Thanks.
Edit:
WebDriver driver = new ChromeDriver();
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("$([name=startDate_submit]).attr('type', 'text');");
Thread.sleep(3000);
// This line doesnt like to run because its hidden
selenium.type("name=startDate_submit", "2015-09-25");
Should this be the way I do this? I just cannot get it working.
just try with this command,
driver.findElement(By.xpath("path")).sendKeys("value");
but make sure you have clicked that path before providing input value. come back if you still have any problem.
Try with available javascript commads like document.getElementById, then set the value.

How to switch to Telerik Radwindow using webdriver (java)

We are testing an application build using Telerik.
A demo of Telerik is available here: http://demos.telerik.com/aspnet-ajax/window/examples/radwindowobject/defaultcs.aspx
Our application is build in a similar way.
In this demo you can see a window with Bing in it. I want to switch to it using WebDriver (Java) to perform actions on objects within it.
I have tried to switchto iframe but WebDriver comes back saying it is not an iframe.
Also tried to get window handles and switchto window but with no luck, it is not treated as a new window. Any suggestions please?
The following code worked for me. I was able to enter text in the bing search field.
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://demos.telerik.com/aspnet-ajax/window/examples/radwindowobject/defaultcs.aspx");
driver.switchTo().frame("RadWindow1");
driver.findElement(By.name("q")).sendKeys("Hello this is my text");
Let me know if this helps you.

WebDriver : SendKeys(Integer) NOT working in Firefox 29

I am using Firefox 29 and WebDriver java 2.41.0 bindings to automate test scenarios. Have one scenario to input an integer to a input-box which was working FINE with Firefox 28 and now failing with v29 i.e latest FF version. The code I wrote for the same is:
int inputString = 123456;
driver.FindElement(By.Id("tinymce")).SendKeys(inputString);
Please help me getting through of this.
This will be the result of this issue:
https://code.google.com/p/selenium/issues/detail?id=7291
Fixed by this revision in the Selenium code:
https://code.google.com/p/selenium/source/detail?r=afde40cbbf5c
Quick test below worked for me. I understand JS is not the right way to do browser simulation, one should always FIRST use webdriver methods since they use browsers native api, but thought it would unblock you while the bug is fixed in selenium
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability(CapabilityType.HAS_NATIVE_EVENTS,true);
WebDriver driver = new FirefoxDriver(desiredCapabilities);
driver.get("http://yizeng.me/2014/01/31/test-wysiwyg-editors-using-selenium-webdriver/");
WebElement frame = driver.findElement(By.id("tinymce-editor_ifr"));
driver.switchTo().frame(frame);
WebElement body = driver.findElement(By.id("tinymce"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].innerHTML = '<h1>Heading</h1>Hello There'",body);
Can you check following points
Can you make sure there are no application changes, I mean the locator is returning single node element.
Can you also post the exception that you are getting. To troubleshoot this problem, need these details.
One thing I do before sending a value to a box is to clear it, also, the value I send is always a string, the parsing should be done by the page/code as you need to validate what the user has entered.
But I do agree with skv, we need to see the actual error being thrown.

Webdriver test doesn't select option from dropdown

i have a registration form for checkout,I have to select a state from drop down,for which i have written a script:
WebElement wb = driver.findElement(By.name("user_data[s_state]")) ;
Select selwb = new Select(wb) ;
selwb.selectByValue("KR");
driver.findElement(By.name("dispatch[checkout.update_steps]")).click() ;
but after executing this script,it is not selecting given value from dropdown.hence i am unable to proceed on next step. Plz help me out....
I can give you a suggestion since I have worked with Selenium webdriver for sometime. The webdriver executes very fastly. Selenium driver doesnt take care whether the page loaded or not. So I recommend you to add code just before the click/selection events to make sure that the page loaded completely. There are options like waitForPageLoad() or checkifComponent exist to make sure that page is loaded properly before the events are triggered. Hope this will help you.
If any wait doesn't help - like suggested before - try to select eg. by index or text.
I've had such wired cases where one of ByValue/ByText/ByIndex method didn't work although others did with particular dropdown.
If you are about to select the drop down use the following:
First make the webdriver wait
Then try choosing the element with the help of
driver.findElement(By.xpath("xpath of the value").select
OR
you can use like the following:
new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("the xpath of the value"))).click();

Categories