Get URL from active Firefox session with Swift or Objective C - objective-c

Is it possible to retrieve the URL from an active firefox session with Swift or Objective-C. So far i was able to retrieve the Name of the actual tab with applescript but not the URL.
What would be the right way?

Not without installing something like Selenium (or, perhaps, only Selenium), AFAIK. If you do use Selenium, you can use various languages to get the "WebDriver"'s current_url property.
Without Selenium, if you want to get kind of clunky (but effective), you can use System Events (AppleScript) to do a command-l (ell) then command-c to highlight the url field and copy it to the clipboard, then access that.

Even with Swift or ObjC, you would still need a Scripting Bridge, and Firefox's scriptability is sparse, as you have discovered. However, AppleScript can do this with either Safari or Chrome:
tell application "Google Chrome"
URL of tab 1 of window 1
end tell
--> "https://www.lds.org/?lang=eng"
tell application "Safari"
URL of tab 6 of window 1
end tell
--> "http://www.nps.gov/webcams-mora/mountain.jpg"

Related

How to wait for element to be visible for Mobile app in QuaMotion

Anyone know "How to wait for element to be visible for Mobile app in QuaMotion".
I wonder if anyone has used Quamotion for automation of mobile app.
thanks in advance
The product manager of Quamotion here.
We implement the Selenium/WebDriver protocol, so you can use the same commands you'd use to wait for an element in Quamotion as you'd do in Selenium.
It depends a bit on which client you are using (C#, PowerShell, Java,...) but the construct is always the same.
For example, in PowerShell, you can use the Wait-ForElement command to which you can pass an XPath expression, a marked statement or a class name.
If you'd want to wait for an element with the text Login, you can use this command:
Wait-Element -marked 'Login'
This will block your script until this element is visible.
If you're using another programming language, let me know, and I'll update my answer.

Automate a button click on chrome://extensions page using selenium webdriver

I'm trying to write an automated test that will automate the process of updating a google chrome extension. I'm not aware of another method of doing this automatically so here is what I'm currently trying to do:
Open the chrome extensions page (as far as I'm aware this is just an html page unless I'm missing something).
Click on the "Update extensions" button
Here is what I have tried having opened the chrome extensions page:
IwebElement UpdateButton = driver.findelement(By.Id("update-extensions-now"));
UpdateButton.Click();
For some reason the button click is not registering. I have tried some other locators such as CSS path and Xpath but they don't work either. Also, when I debug this test, it passes fine so I know it's not an issue with any of my locators. I have (as a test) tried to automate clicks on the other elements on this page and it's the same issue. I can't get a handle on any elements on the chrome://extensions page at all.
Has anyone encountered this or have any ideas as to what's going on?
You can use the Chrome extensions API to auto-update required extension.
Find the file "manifest.json" in the default Google Chrome
C:\Users\*UserName*\AppData\Local\Google\Chrome\User Data\Default\Extensions
There find the update URL of your extension:
{
"name": "My extension",
...
"update_url": "http://myhost.com/mytestextension/updates.xml",
...
}
The returned XML by the Google server looks like:
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='yourAppID'>
<updatecheck codebase='http://myhost.com/mytestextension/mte_v2.crx' version='2.0' />
</app>
</gupdate>
appid
The extension or app ID, generated based on a hash of the public key, as described in Packaging. You can find the ID of an extension or Chrome App by going to the Extensions page (chrome://extensions).
codebase
A URL to the .crx file.
version
Used by the client to determine whether it should download the .crx file specified by codebase. It should match the value of "version" in the .crx file's manifest.json file.
The update manifest XML file may contain information about multiple extensions by including multiple elements.
Another option is to use the --extensions-update-frequency command-line flag to set a more frequent interval in seconds. For example, to make checks run every 45 seconds, run Google Chrome like this:
chrome.exe --extensions-update-frequency=45
Note that this affects checks for all installed extensions and apps, so consider the bandwidth and server load implications of this. You may want to temporarily uninstall all but the one you are testing with, and should not run with this option turned on during normal browser usage.
The request to update each individual extension would be:
http://test.com/extension_updates.php?x=id%3DyourAppID%26v%3D1.1
You can find even more detailed information on exntesions developers site: https://developer.chrome.com/extensions
If you look at the HTML of the "chrome://extensions" page you will notice that the "Update extensions now" button is contained within an iframe. You need to switch to the iframe before trying to register a button click. i.e:
(This is in c#. Note that this code is written from memory so it may not be 100% accurate. Also, you will want to write more robust method. This code just quickly demonstrates that by switching to the iframe, it will work ok)
String ChromeExtensionsPage = "chrome://extensions";
driver.Navigate().GoToUrl(ChromeExtensionsPage);
driver.Switchto().Frame("DesiredFrame");
IwebElement UpdateButton = driver.findelement(By.Id("DesiredButtonID"));
UpdateButton.Click();

Selenium WebDriverJS in browser getting user window object

With Selenium IDE I used this.browserbot.getUserWindow() for getting the window object, but I couldn't find a way doing it with the WebDriverJs.
Using the WebDriverJs is there a way to get the window object?
No, not easily.
SeleniumIDE works in the current browser, whereas WebDriver uses the JSON Wire Protocol to communicate with a potentially-remote browser. Your WebDriver code is not running in the target browser, so the window object is simply not there to be accessed. (If your code actually is running in the target browser, you can get the window object from that in the normal manner.)
You could attempt to serialize the window object and transmit it via Wire: there's a hint on how to do this in this answer. The effort is almost certainly not worth it.

Safari extension options pages with access to background page

I'm developing a cross-platform browser extension, and have based all my code on the Chrome-way of doing this. I have counted on that the background page will be accessible from the options page, which in Safari extensions turns out to be not possible (since there is no such thing as an options-page). You can only access safari.extension.globalPage.contentWindow from within the extension popup, and the background page itself.
Now, I have an options page, which is an html-page within the extension bundle, and so far I haven't found a way for Safari to give it extension "rights". The closest I have come is adding a content script that's only added on the options page. This seems a bit silly, since the html page itself is in the extension bundle?!
Others have suggested using asynchronous ping-pong style message event handlers, and even the canLoad-mechanism (which is "only" able to run in a beforeload-event). I have been able to hack the canLoad-mechanism for synchronous messaging by forging the BeforeLoadEvent:
// Content script (run from anywhere)
var result = safari.self.tab.canLoad(new BeforeLoadEvent, "data")
-> "return value"
// Background page
safari.application.addEventListener('message', function(e) {
if ( e.name === "canLoad" )
e.message = "return value";
}, true);
It's a hack, but it works. However, I am crippled by the message transport serialization, since I need to be able access methods and data on my objects from the background page. Is there anyway around this?
Possible ways that might work but I don't know if possible:
Access options-page window-object from backgrounds page. Is that possible?
Message passing, need to bypass message serialization
Any shared/global object that I can attach objects to and fetch from the options page?
Make Safari run the options.html page from outside the content-script sandbox? It works in Chrome since they are both within the extension-bundle. It's quite annoying that safari doesn't do this too.
Run the options-page from within the popup. This is promising, but it crashes safari (which is very promising!). However, from the looks of it it's just something to do with a CSS animation in my options.html page. The biggest issue is that it has to be able to open an OAuth2 popup, but thanks to being able to programmatically open the popover, it might be a non-issue. However, this option is the most realistic, but I would rather have it open in a new tab.
Any suggestions and hackish workarounds would really help.

LXR, DXR or woboq for WebKit?

Is there anywhere that you can browse the WebKit source code easily and be able to "go to definition" for information about every variable, type, and function?
Something like the Linux Cross Reference, Mozilla's DXR, or woboq Code Browser.
Which specific WebKit port were you interested in? We managed to get the current Qt5 QtWebKit to compile with the code browser :)
http://code.woboq.org/qt5/qtwebkit/