Using Selenium to edit browser opened manually [duplicate] - selenium

This question already has answers here:
How can I reconnect to the browser opened by webdriver with selenium?
(4 answers)
Closed last year.
Say a user opens a tab on their own, and wants to make changes to the data in that tab using an extension which inputs data for them on that page.
From my understanding, Selenium can only have access to browser sessions if they are open with webdriver, which I don't believe works if a user opens a tab manually. Therefore, is there a way for Selenium to interact with such a tab, or should I use something else?

If the tab you opened manually was already part of a browser window that was opened with Selenium/WebDriver, then you only need to switch to the tab to have Selenium perform actions on it. Eg:
driver.switch_to.window(driver.window_handles[-1])
However, if the original browser window was not opened with Selenium/WebDriver, then you can't give it control of the browser later. That would be a major security violation if that was possible.

Related

Can chrome know if there is a window maximized or not in front during selenium automation? [duplicate]

This question already has answers here:
Selenium stops when browser is manually interrupted
(1 answer)
Way to open Selenium browser not overlapping my current browser
(2 answers)
Sending selenium chrome instance to the background using Python
(2 answers)
Closed 2 years ago.
I'm facing a really annoying issue trying to atuomate one project site tests.
The tests goes through multiple pages filling some forms.
I have the following scenarios:
I start the script, the chromedriver is opened and maximized. I keep my focus on the page while script runs. I go without problem through the whole test.
I start the script, the chromedriver is opened and maximized. Now I put a window in front, but this window is not maximized, so I can see in background how the script is filling the forms but my widow focused is another one. I go without problem throught the whole test.
I start the script, the chromedriver is opened and maximized. Now I put another window in front but this time the window is maximized and I can not see the script in background. Now I can go through some of the forms, but it gets stucked in one of them not being able to open some select boxes or writing text.
Things that I have checked/observed:
I'm not able to think a logical reason of this happening. If I run the same 3 steps in firefox with geckdriver they always work.
I have observed that when I switch from my window maximized on top, to chrome, I seem to find a gray page for some ms as it would be not rendered yet, I was able to make this screenshot by recording the screen:
Environment:
I'm using perl with Selenium::Chrome together with ChromeDriver 87.0.4280.20
The site being tested is built on JSF and developers have not included any specfic focus requirement.
This ocurs always using the process described in step 3.
Hypothesis:
Somehow chrome knows if is visible in screen and then its behaivour of elements loaded in DOM changes? I can still see find elements with selenium, but its behaivour on click does not work as expected.
Furthermore, in one of the steps where I was facing this issue, there was a button which would work with:
$driver->execute_script("arguments[0].click()", $element);
But not with
$element->click()

How to handle external applications in a selenium-test?

I am writing a test that verifies that a warning to the user before the user opens a document. If the user says that they still would like to open the document, the document opens in an external application (pdf or word).
But now I have an external application over the browser window, and it messes up for other tests.
So, what are the best practices around this kind of issue? Rewrite of the appliction to allow for not opening documents in test?
Added description:
The problem is twofold.
1) It starts processes (word and acrobat) that fills the desctop and requires resources from the test-slave
2) The external process seems to interfer with other tests since (guessing here) it is located over the browser window.
what i understood from your post is, the document(word/pdf) is opening in the browser window hence you are not able to proceed with further steps. If so, you can verify the Title to make sure the document is opened in browser window and can navigate back using below snippet.
driver.navigate().back();
Hope this helps.
What I understand from the line
'But now I have an external application over the browser window, and it messes up for other tests.'
is that once user clicks on open button a new window opens up (Window based application) since you have mentioned PDF or Word.
You can use robot class in such cases, below code snippet will close the current active window:
Robot rbt = new Robot();
rbt.keyPress(KeyEvent.VK_ALT);
rbt.keyPress(KeyEvent.VK_F4);
rbt.keyRelease(KeyEvent.VK_ALT);
rbt.keyRelease(KeyEvent.VK_F4);
Make sure you deal with sync issues properly so that intended window is closed instead of AUT.

Open a link in new tab using Selenium IDE

I have looked at many answers
Selenium IDE:Opening in new tab and shift focus to new tab not working
How to open link in new tab etc....
posted regarding this question but not even a single one is 100% relevant therefore, I am asking this again.
I need to open three different links:
google.com
yahoo.com
microsoft.com
in three different tabs but under same window and I am using selenium IDE, I know, it is easier using WebDriver but unfortunately I am using IDE. If I use Open it just opens the next link in the same tab and when I use OpenWindow or openWindowAndWait, it just opens the new window which I do not want.
Can someone please help..
There's no command within Selenium IDE which directly relates to Tabs, Selenium IDE is just not built to work with them. There's a post fro ma few years ago which references an answer from a selenium dev stating this (Selenium IDE for Firefox Ctrl-Tab)
The only way to potentially get it working would be to use send Keys to simulate Ctrl+T to open a new tab. There's a post here which gives details on it.

Reuse existing firefox instance with selenium and capybara

currently during debug of test cases selenium is opening a new firefox window, in whatever desktop screen it chooses. I want to be able to have selenium attach to the existing window (and not close the window when the test is over.)
I see this in the selenium documentation
webdriver.firefox.useExisting Never use in production Use a running instance of firefox if one is present
but I do not see how to set it from rails/rspec/capybara
I have looked at the related SO answers, and they are more to do with attaching to a running test. I just want to control where the window is, and be able have the window open with the developer console, so we can see what is going on, and finally have the window stay open at the end of the test
Depends on the issue 2163 it was a feature of Selenium 1 and not implemented to Selenium 2 but still stays in documentation. Check this issue.

How to maintain session in selenium while opening new window

How to maintain session in selenium while opening new window. I am clicking a download button after which a file should be asked to download(IE). But running via selenium it opens a new window asking again to login???
I had similar issues. I don't know your implementation, but maybe you're cleaning cache with each new browser Instance. Try to find why it's opening new Window instead of using same browser instance and just open it's download_window. How you handle default_window can also be the answer you are looking for.