I've tried to maximize the window onPreapre by the command below:
browser.driver.manage().window().maximize();
But it doesn't maxmize the window and there's no error on selenium webdriver logs, actually it seems like the execute has been succeed -
Starting ChromeDriver 2.26.436421 (6c1a3ab469ad86fd49c8d97ede4a6b96a49ca5f6) on port 5814
Only local connections are allowed.
17:14:28.898 INFO - Done: [new session: Capabilities [{count=1, browserName=chrome, chromeOptions={args=[--no-sandbox, --test-type, --memory-metrics, --console, --crash-on-failure], prefs={download={directory_upgrade=true, default_directory=./Users/Idan/automation/tests/downloaded/, prompt_for_download=false}}}}]]
17:14:28.909 INFO - Executing: [set script timeout: 90000])
17:14:28.910 INFO - Done: [set script timeout: 90000]
17:14:28.969 INFO - Executing: [maximise window])
17:14:29.236 INFO - Done: [maximise window]
17:14:29.244 INFO - Executing: [maximise window])
17:14:29.250 INFO - Done: [maximise window]
You can try it with start-maximized flag:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['start-maximized']
}
}
I remember we had a similar issue - what we did is first set the size of the window and then maximize - don't remember exactly why did we apply this workaround, but it works for us:
browser.manage().window().setSize(1400, 900);
browser.manage().window().maximize();
According to your log - you do maximization twice. Maybe the first time it is maximized, and after the second try it is restored down to default size
You can use javascript to do this.
((IJavaScriptExecutor)browser).ExecuteScript("window.resizeTo(x, y);");
'x' and 'y' depends on your screen resolution.
The best way to maximize a chrome app is through JavaScript. Try this:
//Maximizing Chrome App Window.
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("window.resizeTo(1366, 768);");
Change the parameters 1366, 768 according to your monitor settings/setup.
I had the same problem with our browser.manage().window().setSize(1024, 768);, but when I used a better ratio it worked fine browser.manage().window().setSize(1200, 800);
Not sure this will help anyone but hope it does.
Were facing the same kind of problem and solved using this snippet: (Java)
driver.manage().window().fullscreen();
**Screen goes in the fullscreen mode, and you will not be able to see the address bar, all you will see is the content of the page.
Related
Following code hangs for about 12 minutes after clicking on "Print Change"
button and then throws error that element not visible at line:
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")+ "\\exe\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
driver.get(prop.getProperty("https://genpact-qa-smartit.onbmc.com"));
driver.findElement(By.xpath("//*[#id='okta-signin-
username']")).sendKeys(userid);
driver.findElement(By.xpath("//*[#id='okta-signin-
password']")).sendKeys(pwd);
driver.findElement(By.xpath("//*[#id='okta-signin-submit']")).click();
driver.findElement(By.xpath("//a[#id='header-search_button']")).click();
driver.findElement(By.xpath("//input[#id='globalSearchBox']")).
sendKeys("CRQ000000029504");
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
driver.findElement(By.xpath("//a[text()='View Full Change']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//div[#title='Print']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
System.out.println("Clicked on Print Change button");
I am using OS: Windows 10; Browser: Chrome 77.0.3865.90; Selenium: 3.141.59
Any help would be highly appreciated.
Regards,
Surender
First of all for your safety please edit your post removing your username and password that are in your code (and afterwards change them).
As far as your problem is concerned there is a high possibility that:
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
there are more than one elements with the given xpath so the one you want might not be visible.
Therefore you should either be more specific with the:
[contains(text(),' ... ']
or try using the css selectors.
Anyway look up the docs for locating elements and if you still don't find a solution I will be happy to help you again.
Edit: In order to help you I logged in and your solution probably is to replace
driver.findElement(By.xpath("//button[contains(text(),'Print
Change')]")).click();
with
driver.findElement(By.xpath("/html/body/div[4]/div/div/div/div[3]/div/button[1])]")).click();
You specified an implicit wait of 120 seconds , so the code will wait for 120 seconds before throwing in to an exception.
in this case i think the xpath is wrong that's why its waiting for long time (may be there is some extra space in between the text print change). Use any xpath identification tool to check whether the xpath is correct or not
i hope the following code may work
driver.findElement(By.xpath("//button[contains(text(),'Print')]")).click();
I am using Selenium 3.14 and ChromeDriver 2.42 with Chrome 69.0. I was always using this code to drag and drop, which worked until recently, when tests started failing:
$driver->action()->clickAndHold()->moveByOffset(100, 0)->release()->perform();
After some Chrome update, it just stopped dragging. I also tried dragAndDropBy() function, with no luck. (dragAndDrop() is not an option because I need to move inside one element).
After hours of experimenting I was able to narrow the issue down to this weird thing, when using moveByOffset with bigger number, like 100 in my example fails, it just weirdly bounces in place. But when I tried to move it only by couple of px, it worked.
This is the code I ended up with:
$driver->action()->clickAndHold()->perform();
for($i = 0; $i < 10; $i++){
//moving this 10 times by 10 px instead of once by 100px
$driver->action()->moveByOffset(10, 0)->perform();
}
sleep(1);
$driver->action()->release()->perform();
I just want to share this, if somebody encountered similar issue.
sometimes in my test done with Selenium 2.41 and tested with Firefox 28 the execution hangs waiting for page to load.
This is the wait condition:
int time = 30;
WebDriverWait wait = new WebDriverWait(webDriver, time);
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
wait.until(pageLoadCondition);
It's supposed that after 30 seconds this method will throw a TimeoutException, but it's not, sometimes hangs forever.
This is the stacktrace produced in these situations:
java.lang.Thread.State: RUNNABLE at
java.net.SocketInputStream.socketRead0(Native Method) at
java.net.SocketInputStream.read(Unknown Source) at
org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:160)
at
org.apache.http.impl.io.SocketInputBuffer.fillBuffer(SocketInputBuffer.java:84)
at
org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:273)
at
org.apache.http.impl.conn.LoggingSessionInputBuffer.readLine(LoggingSessionInputBuffer.java:116)
at
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
at
org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at
org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at
org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)
at
org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251)
at
org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:223)
at
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at
org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at
org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:682)
at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486)
at
org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at
org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at
org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:322)
at
org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:301)
at
org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.execute(NewProfileExtensionConnection.java:165)
at
org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor.execute(FirefoxDriver.java:362)
at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568)
at
org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:504)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver$1.apply(TAORobotWebDriver.java:6227)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver$1.apply(TAORobotWebDriver.java:1)
at
org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver.waitToLoad(TAORobotWebDriver.java:6230)
at
es.tao.commonservices.selenium.tests.TAORobotWebDriver.handleWaitToLoad(TAORobotWebDriver.java:6110)
I have set this preference for firefox profile, but it's still not working:
ffProfile = new FirefoxProfile();
ffProfile.setPreference("webdriver.load.strategy", "unstable");
Also have this properties set:
webDriver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
webDriver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
You may want to try Firefox 27.01. I upgraded to Firefox 28.0 and it seemed to break some tests I was doing using watir-webdriver. I went back to 27.01 and the tests ran again(if you go back download the whole install package as the setup only, does not seem to let you turn off auto-update so it updates itself to 28.0).
The fails were using hover and find_element.
Found an unresolved bug: https://code.google.com/p/selenium/issues/detail?id=6955 - if you can, please provide a test case, primarily a reduced host page with minimal scripts where the problem still occurs so it can be repeated reliably and traced down.
Sometimes I question myself if Google uses their own tools at all.... they should have run into that bug ages ago considering how huge that company is.
I've been using Selenium 2/WebDriver through Ruby 1.9.2, and directly through FireFox it works fine. I wanted to use HtmlUnit so it's faster and headless, so I'm trying selenium-server-standalone-2.17.0 as it should in theory require no code changes, and also I want to start using Java/groovy with HtmlUnit.
The problem is that half the time or more, a test fails because when I click a button and switch windows, the HTML (and title) in the new window is the same as the old one.
I added lots of debugging output to my function to try to narrow it down:
def switch_to_newest_window()
assert(#driver.window_handles.size > 1, "only one window")
print "switch to newest window, handles=#{#driver.window_handles}...\n"
print "current handle: #{#driver.window_handle}\n"
print "#{#driver.window_handles[0]}\n"
print "#{#driver.window_handles[-1]}\n"
print "title: #{#driver.title}\n"
save_file("first.html", #driver.page_source)
#driver.switch_to.window(#driver.window_handles[-1])
print "new handle: #{#driver.window_handle}\n"
print "new window title: #{#driver.title}\n"
save_file("second.html", #driver.page_source)
end
And the relevant output is:
switch to newest window, handles=["36543124", "1755893858"]...
current handle: 1755893858
36543124
1755893858
title: Create FlowSet
new handle: 1755893858
new window title: Create FlowSet
So it's correctly switching windows, but the HTML is the same! If you diff first.html and second.html, there is no output.
I'm also a ruby noob so I may well be doing things the hard/slow way or incorrectly.
Other details:
running on Windows 7.
Selenium Server server-standalone-2.17.0
Server output when starting HtmlUnit session:
13:03:12.292 INFO - Executing: [new session: {platform=ANY, javascriptEnabled=true, cssSelectorsEnabled=false, browserName=htmlunit, nativeEvents=false, rotatable=false, takesScreenshot=false, version=}] at URL: /session)
Thanks very much in advance for any help.
Joel
I'm trying to run a basic test in Internet Explorer via Selenium-RC/PHPUnit, and it always returns with
# phpunit c:\googletest.php
PHPUnit 3.4.15 by Sebastian Bergmann.
E
Time: 35 seconds, Memory: 4.75Mb
There was 1 error:
1) Example::testMyTestCase
PHPUnit_Framework_Exception: Response from Selenium RC server for testComplete()
.
Timed out after 30000ms.
C:\googletest.php:17
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Paul#PAUL-TS-LAPTOP C:\xampp
#
The last command in command history is waitForPageToLoad(30000). The same test runs fine and completes in firefox. How can I get this test to run and complete in internet explorer?
Thanks
There's an open bug in selenium that causes waitForPageToLoad to sometimes timeout on IE.
http://jira.openqa.org/browse/SRC-552
It's marked as occurring on IE6, but I'm experiencing the same error in at least IE9.
A workaround is to wait for e.g. a specific DOM-element on the page that is loading instead of using waitForPageToLoad. For example: waitForVisible('css=#header')
Try going into Internet Options and turn off Protected mode under the security tab. You may also want to decrease the security level for the Internet zone.
I've turned off protected mode and looks like it helped.
If it is acceptable to customize the client driver, here is the Python implementation for your refernece:
def open(self):
timeout = self.get_eval('this.defaultTimeout')
self.set_timeout(0)
self.do_command("open", [url,ignoreResponseCode])
self.set_timeout(timeout)
self.wait_for_page_to_load(timeout)
def wait_for_page_to_load(self,timeout):
# self.do_command("waitForPageToLoad", [timeout,])
import time
end = time.time() + int(float(timeout) / 1000)
while time.time() < end:
if self.get_eval('window.document.readyState') == 'complete': return
time.sleep(2)
raise Exception('Time out after %sms' % timeout)
I just use DOM attribute document.readyState to determine if the page is fully loaded.
IE 9+ intermittently throws a timeout error even the page is fully loaded, for more details.