I'm having a bit difficulties with chrome driver and selenium, i have selenium.support version 3.141.0 and chrome driver version 2.43.0.
during a test run i click on a button which redirect me to a new page, so i use WebDriverWait.until() until a condition that check if a certain element exist is met but for reason the window is flashing for a few seconds and later just close.
_wait.Until(d => d.FindElements(By.XPath("//div[#id = 'expression']")).Any());
edit: i found that the window is flashing and later shut down after this line which come after the wait.Until.
_driver.FindElements(By.ClassName("connections-list")).First();
the line return Sequence contains no elements although the element is visible and it still doesnt explain why the window shut down
Suggest you to use External supported library, And check your scenario with same:
Library : SeleniumExtras.WaitHelpers
You can use it as:
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(WebElement));
Related
First I tried to add extension directly from chrome webstore, but problem is alert popup which appears after you click "add to chrome" is not reachable by selenium. After I wanted to try using options.AddExtension, but multilogin profile starts before selenium takes control so this method is useless. I know that I can manually import .crx for every profile but there are thousands of profiles and I need to automate process of installing extensions. I don't know what to do, I heared there's option to reach popup alert in chrome webstore but can't find it. Or maybe there are other ways to install extension after browser started? I'm glad for any help or advice
I have 2 possible scenarios for you, hope that works out since I don't have direct access to this specific need you have because the extensions may differ.
Not using Selenium, you gonna start the chrome process using the class Process and add the flag --load-extension= to load the specific profile/extension that you need. You can see the entire comma here. To sum, you can use this snippet below to load:
chrome --user-data-dir=/tmp/someuniquedirname --load-extension=path/to/extension --no-first-run //Note: some flags may change between versions of chrome, see full documentation
After defining the extension and start chrome, you can now get hold of the process with Selenium by using another flag: --remote-debugging-port=http://localhost:[localporthere]. After that, start the process than tell to Selenium to get hold of that process with the port and do your job.
Another way is to start the process installing the extension manually and in another Thread use some Automation UI (Teststack.White or FlaUI) to click on the popup you have. I can't extend here in the entire code for this solution because it will go to a opinion-based answer, but you can check on FlaUI for that use, and follow that path:
Selenium starts the program, click on the install extension and wait for the popup to show-up;
New Thread;
FlaUI gets hold of the process that you already start;
Using UIElements, click on the "ok" button you need;
FlaUI drops;
Back to the main thread.
If you need any clarifications about the solutions above, just comment and I'll try to help you further.
So this has me quite mixed up.
We have a testing framework using Selenium, Specflow and C#. Currently running Selenium 3.13.1 (Just upgraded yesterday to see if the older version (3.11.2) was the issue)
The issue (only when Emulating a mobile device in Chrome):
When running tests locally all is well, buttons are clicked and the test passes.
When running tests remotely on the Jenkins slaves it works some of the times .i.e. sometimes I get a click and sometimes I do not.
When the Jobs are run as per schedule some of the tests fail consistently (these being tests that run perfectly well when run locally).
I have tried adding a Sleep of 5 seconds, however this did not help.
One thing that did work is changing Click() to SendKeys(Keys.Enter).
Executing javascript to click the button works well too however I do not wish to change from click for 2 reasons. 1. This is the closest action which simulates user input and 2. This works well locally.
Chrome versions on the Jenkins slaves are in line with my local version (67.0.3396.99) and Chrome driver is also inline (2.40.565498).
Chrome driver has been updated yesterday since I have tried with version 2.38 and 2.39 but to no avail.
Has anyone come across this issue and found a solution?
P.S. When running tests not in mobile emulation I have no issues with clicks both locally or on Jenkins.
i had the same problem.
After I allowed PopUps in my Browser the click and clickAndWait Event works fine.
Maybe you can change the browser too.
Best Regards
For anyone who has this issue, this is the current relevant answer at this point in time.
This was not an issue with the framework we are using but an issue with chromium and chrome driver.
The issue/bug link can be found here (this is the known issue quoted below).
Also if you check the documentation for chrome driver mobile emulation, it is mentioned on the first line as follows
Note that Mobile Emulation is subject to this known issue.
This answer does not help solve the issue per se but gives the reason why it is happening. The "best" workaround I have found is using JS to click and so on. In our case we stopped using mobile emulation for now since clicking with JS does not really emulate a real click. As new versions of Chrome and ChromeDriver are realeased I will keep updating until there is a fix for it.
Hopefully you will waste less time than I have searching around for an answer :)
Selenium for Chrome and Firefox, coding in C#, will not handle switching over to the new tab that is opening during my automation test. I don't think it focuses on the new tab open because when I run my program completely, I receive this error: "out of range" exception and "Index was out of range. Must be non-negative and less than the size of the collection."
I've tried using:
driver.SwitchTo().Window(driver.WindowHandles.Last());
and
driver.SwitchTo().Window(driver.WindowHandles[1]);
driver.SwitchTo().Window(driver.WindowHandles[0]).Close(); // close the first tab
System.Threading.Thread.Sleep(5000); //Wait 5 seconds just in case
driver.SwitchTo().Window(driver.WindowHandles[1]); //Makes sure I'm on the correct tab
but there is no luck. If I don't close the first tab, I receive the error: "NoSuchElementException:Unable to locate element:{method...}" which I assume is correct because the focus is still on the first tab. Any help would be greatly appreciated. Thank you.
Once you've closed tab[0], the old tab[1] becomes the new tab[0], so you should be switching to tab[0].
Selenium operates in the background so the window does not need to be in focus while it is running. This also means that Selenium will never change the focus back to the browser window. If you are watching the window while your code runs however you should be able to see the browser changing tabs.
Selenium Webdriver for Internet Explorer 11 is not creating a new window handle when my app opens a new tab.
The problem is similar to this , which was a problem with the window handles disappearing in a fraction of a second, but in my case a new window handle isn't even created in the first place.
I used the test code from that link to check for disappearing window handles, but it never created another window handle when a new tab was opened, so the test only displayed the first console output and never the second part.
I tried using:
driver.SwitchTo().Window(driver.WindowHandles.Last());
but the Selenium Webdriver focus stays on the first tab, because I believe it isn't creating a new handle for the new tab.
Also, tried this:
driver.SwitchTo().Window(driver.WindowHandles[1]);
and that results in an "out of range" exception and "Index was out of range. Must be non-negative and less than the size of the collection."
If I change the [1] to a [0], then obviously I do not get the exception because the focus is just set to the first tab.
Based on my testing with the test code in the link I provided and my own attempts, I believe that new window handles are not being created.
I tried resetting IE11 and then only changing the settings as described on Selenium's website including adding the registry key, which I used Helium's solution to that found here.
Also, I read some suggestions of adding the websites that I am opening to the Trusted sites list in IE, but still no go.
Any help is appreciated. Thanks.
Hopefully this will help someone going forward...
I have been researching this after having the same issue and whatever I tried it did not resolve it!
In the regedit I added the 'BF_Cache' -> 'iexplorer.exe', added '2500' set as '3' in the zones 0,2,3,4 (was already present in zone 1) & Set the 'protected mode' to enabled but no luck... My new window would open correctly through Selenium but when debugging I confirmed only one handle was available!
But... After I nearly gave up - I decided to run visual studio as an
admin. And as if by Magic Selenium picked up that there was more
than one window handle!
Here's a workaround I managed to use.
You can use javascript to open a new window. It will give you the handle.
string javaScript = "window.open('" + url + "','_blank', 'resizable=yes, scrollbars=yes, titlebar=yes, width=1280, height=680, top=10, left=10');";
jsExecutor = (IJavaScriptExecutor)ieDriver;
jsExecutor.ExecuteScript(javaScript);
I know this issue has been addressed a lot, but I haven't found a problem similar to mine, so please tell me if there's a solution.
I'm using selenium webdriver (chrome) and C# to test a web application.
In the application I have a button, which opens a windows file dialog in order to select and upload the file.
I am using Click() to click on the button and SendKeys() to paste the file's path in the windows dialog and to hit "Enter".
I'm not trying to control the dialog with selenium.
It's successful most of the time, but sometimes the dialog isn't opened once the button is clicked and it seems to be frozen for several minutes (it's impossible to click the button manually as well), but the test resumes as if the dialog had been opened. After 2-3 minutes the windows dialog finally appears, but needless to say that the entire test is messed up.
It is not a problem in the program itself, as the problem never occurres when the click is preformed manually.
What could be the problem and how can I solve it?
Please have in mind I cannot change the program I'm testing.
Thank you
You can do it without White using Microsoft UI Automation directly.
Without TestStack White. No sense to use the whole library for one window automation. White is wrapper only.
var FirefoxWindowElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty,"MozillaWindowClass"));
FirefoxWindowElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty,"#32770"))
//You can navigate directly to input field or just use the keyboard because input field is always focussed
SendKeys.SendWait("YOUR FILE PATH here");
Keyboard.Press(Key.Return);
What if you create a wait for dialog?
public void waitForElement()
{
while(!yourDialogElement.Displayed)
{
yourButtonElement.Click()
System.Threading.Thread.Sleep(1000) // sleep for 1000 milliseconds
}
}
You will probably want to build a try/catch into that button click, and perhaps build a counter into your loop and pass a timeout limit.
Let me know if this works or if you need more help!
You should consider adding a library called WHITE to your framework. This acts like Selenium but for Win32 applications and can handle most types of Windows dialog objects via Microsoft UI Automation.
With WHITE set up, you can add a method at the point in your code where the button is clicked by Selenium that opens up the dialog window. This method can poll for the presence of the dialog and if, after a set time, the window does not appear you could either fail the test there and then or try clicking the button again.
You could also poll indefinitely until the window appears if you are confident it always will. I would set an upper limit myself though to 5 minutes or whatever you feel is right here to prevent some sort of infinite loop situation.