Issue
I am using ChromeDriver to write tests for Android Chrome browser. I use C#. My goal is to use few chrome tabs in parallel. When one page stuck by loading some data or by doing some calcaultion I want to switch to another tab and do another tests, and time to time do some checks: is previous page already loaded, and if yes do another work on it.
Issue: When you set driver.Url or Click on element which load another page your thread stuck until whole page get loaded. It is not ok for me. But I found workaround, I can execute script with timeout like this:
driver.ExecuteScript(string.Format("setTimeout(function() {{ location.href = \"{0}\" }}, 150);", url));
and now at least my C# thread is not stuck.
Now I need to have way to check is page loading complete or not. Theoretical solution: Before executing code above I can get HTML element from document and check some it property, and after new page get loaded and I ask for any property of old element (which do not exist any longer)- I will get StaleElementReferenceException. So my plan sounds good, but it doesnt work. When page is laoading and I ask property of element - my tread is just stuck until page get loaded. I used fiddler proxy to increase time of page loading to have enough time to investigate this issue (I freeze page loading and slow down my connection speed through fiddler). Also I tried to not access any DOM element, but just execute script like "return true;" - same issue it stucks until page get loaded.
Is there any way to not wait for page load? Maybe Is it possible to connect to different tabs with different chromedriver instance? I will appreciate any sugestion!
Version of ChromeDriver: 2.27.440174 System1: Windows 10 x64 System2: Samsung S6 Android 6.0.1
Update 1: I found https://github.com/bayandin/chromedriver/blob/e9a1f55b166ea62ef0f6e78da899d9abf117e88f/chrome/page_load_strategy.h where I can see three types of behaviour: Normal, None, Eager; Seems by default ChromeDriver use Normal. Which means wait until page get loaded. I need to use None - which means do not wait anything (exactly what I need) but I can't make it work. I have tried both:
chromeOptions.AddAdditionalCapability("webdriver.load.strategy", "none");
chromeOptions.AddAdditionalCapability("pageLoadStrategy", "none");
I got next error: "unknown error: cannot parse capability: chromeOptions\nfrom unknown error: unrecognized chrome option: pageLoadStrategy\n (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64)"}
Solution
Here is my solution:
private class ChromeOptionsEx: ChromeOptions
{
public override ICapabilities ToCapabilities()
{
var r =(DesiredCapabilities)base.ToCapabilities();
r.SetCapability("pageLoadStrategy","none");
return r;
}
}
Use ChromeOptionsEx instead of ChromeOptions. These code lines:
chromeOptions.AddAdditionalCapability("webdriver.load.strategy", "none");
chromeOptions.AddAdditionalCapability("pageLoadStrategy", "none");
doesn't work because it will be added to ChromeOptions but pageLoadStategy is not chrome optionts, it is capability. Chrome driver expected t find it in a root of capability. Explanation: ChromeOptions generate next map of capabilities:
- {[browserName, chrome]}
- {[version, ]}
- {[platform, ANY]}
- {[chromeOptions,Dictionary2[System.String,System.Object]]}
- {[pageLoadStrategy,none]} <-------- we should add it here and my code do this
where chromeOptions is
- {[args,ReadOnlyCollection1[System.String]]}
- {[binary,]}
- {[androidPackage, com.android.chrome]}
- {[pageLoadStrategy,none]}<-------------------- AddAdditionalCapability add value there it is no ok
Answered By - GDocal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.