C# Selenium how to interact with chrome extension - c#

I have successfully loaded my chrome profile with selenium that has pre-installed extensions.
The extension in question is called Private Internet Access, but i have tried others and cannot communicate with them
I am trying to figure out how i can open the extension below and enter username&password and click login button. I have tried finding the elements in by id and class but it doesnt find them. Can someone point me down the right line for this. Thanks

I've not had the ability to try this - however I've done a lot of work with Selenium and I've created my own chrome extension.
That extension popup in the top right actually a different web page. You won't be able to interact with it due to how it's presented, but you can navigate to it.
Try this:
Open up your extension, right click anywhere and select Inspect. This will open up devtools for the popup.
In devtools, go to the console and type document.url. This will give you the URL of that popup page. (you'll also see it at the top of the title bar)
That gibberish-looking bit in the middle doesn't change - it's your chrome extension identifier. From when I created my extension and 18 months worth of updates (including migrating from chrome extension manifest v2 to v3) it has not changed for me. I think you'll be safe to use it.
Go to that URL to make sure it works. In my case it's chrome-extension://ojhcleddagaoaplflbafhpekcciikdop/popup.html
You'll notice you'll lose some of the page styling compared to the popup. When you design the popup you give it fixed dimensions - when you open it as a normal webpage, you lose that and everything gets stretched.
Finally - for your automation - put that chrome-extension:\\ url as the first step in your selenium script and do your sign in. Then, carry on with the rest of your test.

Related

Duplicate elements in DOM when running Selenium browser tests

This is a really weird one which I've never seen before and it's difficult to google.
We have a single page app which has internal tabs (not Chrome tabs, pure html simulated tabs in the app). We have end to end Selenium C# tests which run fine when using a single tab. We created some test which run with two html tabs open, and they failed. They failed because a modal with a Open button in it was duplicated & when the test went to click it, it clicked the original not the duplicated and threw an error. There should only ever be one instance of the modal and its components, in fact when you run it as a normal user thats exactly what happens. Here's the scenarios:
Running locally, as normal browser session, two application tabs open, open the modal dialog, one instance of the Open button in the DOM.
Running locally, debug run Selenium C# Visual Studio, two application tabs, open the modal dialog, two instances of the same open button in the DOM, test fails as code is looking for the 'first' one and error is 'another element will get the click'.
This is an Angular 4 SPA project - never seen anything like this before. There are elements in the DOM being duplicated depending on the browser mode. Has anyone else seen this?
Not sure if this is a problem with our app - which case why does it not do this when we run as a normal user? Or if its a problem with how we are launching Chrome from the test suite - we're not specifying any Chrome options when new'ing up a ChromeDriver instance.
'another element will get the click' doesn't mean that there is another element for the specified selector. It usually means that there is another element ON TOP of it (hiding it). I would recommend you creating screenshot right before and after the click and manually inspect if the element is indeed visible at that moment.
Also check if the element you are selecting is not by accident 0,0 size, and when a user clicks, click is received by a child or something like that

How can I remotely take an accurate screenshot of a webpage by URL without WebBrowser?

I tried WebBrowser but any solution related to WebBrowser I find uses the exact same codes, WebBrowser.DrawToBitmap
Problem with that is, it gives out inaccurate results depending on URL, to what page actually would look like, sometimes even blank pages.
So I am looking for any alternate solution to WebBrowser if there is any.
It needs to run in background, as in not open any browser on screen, render it in background with all scripts and get an image.
If I understand what you're trying to do, you might be interested in a framework called PhantomJS, which is a WebKit "browser" engine which runs the pages without visually rendering them. It can be used to capture screens.
Now this technique requires JavaScript, but there is something called Selenium WebDriver to help you wrapping that. Users here at SO posted a simple example and this comment looks useful as it contains the list of required Packages.

Browse through a pop-up?

I want to test the links that appear in a pop up in a website after pressing a button. The problem is that I dont know how to do it. I dont know the name of any buttons of the popup, and even dont know if the watin can navegate through it.
I used to check links in a website searching the button by the name (using development tool from IE to search the name of the buttons), but with the pop up I dont know.
How can i do it? There is a function to work with pop ups? How can I get the name of the elements of the pop up?
All website pages are html, javascript and css - all human readable.
Try viewing the source.
ps They are readable unless they are Flash type applications.
Install the Web Developer extension for Firefox, right-click on the element, choose Inspect Element.
You have to attach to that popup. Treat it like a normal IE window. I don't remember correctly, but try something like that:
var popup = IE.AttachTo<IE>(Find.ByTitle("Title of the popup"));

How to pop a web browser from Silverlight OOB?

I want to pop a web browser popup window, with a given url, from Silverlight.
When running within the browser I use HtmlPage.Window.Invoke() to run a javascript and its window.open() in the host browser. Works fine.
But when I run out-of-browser (OOB) this technique obviously doesn't work. So, what to do?
Silverlight 4 has this new WebBrowser control for use when running OOB. It works fine, but I have only been able to run it in a child window within the silverlight application boundaries.
Then there is this hyperlink trick. Also works, but it creates a new tab in the current browser-instance. Not exactly what I want either.
Anything I have missed?
(Alternatively; is there a a way to make the hyperlink pop the url in the same browserinstance and tab every time? instead of creating new tabs.)
Bit of a long post this. Sorry about that and thank you for your patience.
The link you posted to creating a derived HyperlinkButton is the only one I know of. Maybe play around with different TargetName values to see which one works like you want? "_blank", "_new", etc... - one of them may be what you want.
The trouble is that different browsers (when set as the default browser) may do different things, so be sure to try this with IE, Firefox, on a Mac, ...

How to detect a rightclick in an application

my objective is to attach a context menu (vista and win7) whenever user right clicks a picture/file.
I've got the file portion down (ie, they right click on a file and my menu shows up) but I am having trouble understanding what I would need to do in terms of right clicking in firefox or ie .
I am trying to add a context menu whenever someone right clicks on an image file in IE or firefox. is that possible?
If you want to plug in to what happens inside the user's browser, you should probably write a browser extension to do that, instead of trying to hack up something awful that sort of does what you want maybe.
The best solution would be to develop a plug-in for the browser used by your user, whether it be for Internet Explorer, FireFox or Chrome etc..
Trying to create some sort of hack will only lead to a bad experience for your user so it's better to develop something that would work properly.
Here's a few links to get you going in the right direction:
Google Chrome: http://www.mattcutts.com/blog/write-chrome-extension/
Mozilla FireFox: https://developer.mozilla.org/en/Gecko_Plugin_API_Reference/Plug-in_Development_Overview
(I can't seem to find any for Internet Explorer)
I'm sorry i cannot give you a definitive answer but hopefully this should get the ball rolling for you at least.
is that possible?
NO
For Browsers: You need to develop an extension for each browser you want to support
For Desktop: http://www.codeproject.com/KB/cs/dateparser.aspx (ignore all the stupid istruction about how to catch the datetime )

Categories

Resources