Chrome extension to search a website? - google-chrome-extension

I'm trying to create a google chrome extension (I'm almost a newb at programming, although I understand the basics, somewhat) that will search a video streaming site for the title that you enter. The site is somewhat slow, and going through a page or two to get to the sites' search bar can be a pain. I would (for now) like this extension to tie into the sites' existing search url. Here is part of the URL. When you leave the search field blank and search, this is the resulting URL
anisrch_title=&op=srch&anisrch_cat=
When you actually search for something, it simply inserts the search term as follows:
anisrch_title=(SEARCH TERM HERE WITHOUT PARENTHESES)&op=srch&anisrch_cat=
As I mentioned before, I am a programming newbie, and am unfamiliar with all sorts of programming techniques. How would I go about making an extension that redirects you to the URL + the search term inserted into the appropriate place?
For example, upon clicking the extension Icon, a pop-up appears with a text field and a "Go" button.
Textfield input = SearchTitle
And upon clicking the "Go" button, the extension redirects you to the full link of:
anisrch_title=(SearchTitle)&op=srch&anisrch_cat=
Please be patient with me, as I am a newbie at coding and I am still learning. The site I am making this for is strained by heavy load, and insufficient server resources. Could someone please walk me through this?

For example, upon clicking the extension Icon, a pop-up appears with a
text field and a "Go" button. Textfield input = SearchTitle
Use a browser action (https://developer.chrome.com/trunk/extensions/browserAction.html). The popup of a browser action can be a html page. Just put your text field, go button, etc in popup.html.
And upon clicking the "Go" button, the extension redirects you to the
full link of: anisrch_title=(SearchTitle)&op=srch&anisrch_cat=
redirect? Did you mean opening the search page in the current tab? If that is the case, use chrome.tabs.update (https://developer.chrome.com/extensions/tabs.html#method-update) in your handler of onclick for the button (say your button id is go and text field id is query). Because of CSP (https://developer.chrome.com/trunk/extensions/contentSecurityPolicy.html), you must place your JavaScript code in a separate popup.js and refer to it in your popup.html.
document.getElementById('go').addEventListener('click', function() {
chrome.tabs.update({url: 'http://yoursite.com/path?anisrch_title=' + document.getElementById('query')'&op=srch&anisrch_cat='});
});
If you prefer opening a new tab, use chrome.tabs.create instead.
If you're not familiar with basics of Chrome extensions, the Getting Started tutorial will help you much: https://developer.chrome.com/extensions/getstarted.html.

Related

Python Selenium login with no source code/html/dom (cursor blinking on username)

I have a website (private, sorry) that I'm trying to log into automatically but the login page has no source code available so am unable to assign/find specific elements.
The cursor is blinking on the Username input field, so trying somehow to start typing then tab to password field and then enter.
I've tried the following three different methods, neither fills in any text.
ActionChains:
actions = ActionChains(driver)
actions.send_keys("*username*")
actions.perform()
Passing info to the url itself:
driver.get("https://username:password#my_website.com")
By active element:
active_ele = driver.switch_to.active_element
active_ele.send_keys("test")
I'm guessing your target page is protected by Basic Authentication, and what you're calling the "login page" is not an actual "page", but rather the browser's Basic Authentication dialog box. This "pop-up box" is not an actual page element, so you can't manipulate it with Selenium's page-element API.
In my own Selenium code, with current Chrome (version 90), the "https://username:password#my_website.com" URL does actually work to open the target page. However, it doesn't "fill in any text" like you said; it just directly opens the protected page. Also, a "https://username:password#my_website.com" URL doesn't work in the browser address bar itself; it only works in the Selenium API. Also, my tests are in C#; FAIK the "https://username:password#my_website.com" technique might not work in Python.
Note, Chrome removed the "https://username:password#my_website.com" feature for years, but then they brought it back, sometime before November 2019, when I discovered it; but they only brought it back for the Selenium API, not for the browser address bar.

How to follow a link that is actually a click button

I need to fill a form aproximately 100 times a day. I tried with selenium but it is quite slow because it is using a web browser. It's working quite well with mechanicalsoup until I need to click "Accept" button. Clicking it activates other tables that need to be filled but are inactive before clicking this button. I tried to point to the button and then br.follow_link(button) unsuccesfully. I attach the piece of HTML that I need to fake. I'm looking for a way to produce the effect of clicking avoiding using Selenium.
Aceptar
Sounds like you need JavaScript capability so the button's click would render the tables, but MechanicalSoup doesn't do Javascript.
MechanicalSoup's docs says:
MechanicalSoup automatically stores and sends cookies, follows redirects, and can follow links and submit forms. It doesn’t do Javascript.

Chrome Extension, trigger click on the icon

I searched on Google and StackOverflow, and I was not able to find a solution to my problem (to my greatest surprise).
I'm looking to display the popup, exactly like when the user click on the icon of my extension, but via javascript.
The idea behind it is simple : On a specific page, I inject a button and add an event listener on it ("click"). When the user click on that button, I'd like to display the tooltip, simple as that :)
... but I can not find anything related to it. Any idea ?
Thank you in advance.
Opening the popup is impossible without user interaction. For good reason too, remember that no one likes popups that open themselves. What you can do is inject your popup onto the site the user is at, through a content script.
https://developer.chrome.com/extensions/content_scripts
As per your description,
On a specific page, I inject a button and add an event listener on it ("click"). When the user click on that button, I'd like to display the tooltip, simple as that :)
I think what you need is just chrome.pageAction, it's similar to browserAction, while represents actions that can be taken on the current page, but aren't applicable to all pages.

SharePoint Dataform webpart redirection issue

I have two web parts in my sharepoint aspx web page. One is Content editor web part and the other is data form web part.
In data form web part, I have a data view and I need to pass a parameter "id" to this dataview which will show the project details in the data view. I tried to use a value from a control as a parameter and never had a success. I did googled a lot last few days and haven't found any solution. It would be great, if someone show me a way to use the text from a control (may be a text box or select control). if someone have a working sample, please share. Alternatively I have used a query string as a parameter (eventhough I prefer to use text from a control). We need to pass a query string called id. For example, I am navigating to http://localhost/pages/1.aspx?id=7. This will show the project details of project id 7 in data form web part. this works fine.
I need to provide an option to user to enter the project id instead of modifying the query string in url. To achieve that I used content editor web part and I have a text box text1 and a submit button (html controls). The user will enter project id in the text box provided and will click the submit button to view the project details in dataview. The submit button javascript code has the following code:
url = 'http://localhost/pages/1.aspx?id=7';
alert (url); //alerts as http://localhost/pages/1.aspx?id=7
window.location = url;
For testing purpose, I just hardcoded the url. However, clicking the submit button is not redirecting to http://localhost/pages/1.aspx?id=7 or something happens during redirect. The page just reloads once. i.e., if I am in http://localhost/pages/1.aspx?id=12 and clicking the submit button reloads the page http://localhost/pages/1.aspx?id=12 instead of navigating to http://localhost/pages/1.aspx?id=7.
Without data form web part, the redirect works fine. Kindly help.
Thank you

Trouble attaching to a javascript window with Watir

I am new to Watir, and am working on developing a testing tool for my work.
I have run into a problem that I cannot seem to solve, even after checking several sites.
The javascript window creation is below: (the window created holds a pdf in a window, so the only "buttons" are the minimize, maximize, close)
<a id="LogIn_HyperLink2" class="ms-WPTitle" onclick="javascript:var win = new Window({className: 'spread', title: 'Security Statement', top:0, left:1, width:750, height:365, url:'--redacted--/security.pdf', showEffectOptions: {duration:1.0}}); win.setConstraint(true, {left:10, right:20}); win.showCenter(); return false;" href="--redacted--/security.pdf" style="color:#6699cc; font-weight:bold;">Security Statement</a><br>
I have tried using both
puts browser.modal_dialog(:title, "Security Statement").exists?
puts browser.javascript_dialog.exists?
both have returned 'false'
What approach should I be taking to attach to this new window, or more directly: How can I close this new window?
You can see the page at this link (IE only)
If the window holds a PDF file it's a browser window, not a modal javascript popup (alert, confirm, prompt)
It's defined to start without all the normal menus etc active, but it's still a browser window. You can attach to it as described in the Watir Wiki section about new browser windows, using the url or the title since you know both of those (given the HTML you showed us).
If you are using Watir-Webdriver use it's window switching commands. Right now the watirspec for that is your best reference to the methods supported and how they work.
EDIT
Thanks for the link. While the above would be true for a new browser window, that's not what you are faced with. What you have there is all inside the browser HTML, created in the DOM on the fly with javascript. It's all standard HTML elements, easily interacted with once you know what's going on (this is actually IMHO easier to deal with than a popup or separate window)
Use the IE developer tools, after you click the link that makes that 'window' appear, click the icon in the toolbar of the dev tools to refresh the DOM in the dev tools and you will be able to see that.
The outermost container appears to be a div of class 'dialog', which is unique in the DOM at that point.
The window controls are three divs under that one, with classes 'spread_close', 'spread_minimize', 'spread_maximize'. There are three tables that hold the graphic elements for the top, sides, and bottom of the 'window' but there is ZERO actual content there, it's just a visual windowframe.
There is also an iframe that superimposes that window, which is I think were the content would be (I can't get it to load, maybe because I'm not authorized for it or something)
If you just want to close the window, try this:
browser.div(:class => 'spread_close').click
Since this is coming into existing due to a bunch of client side JS code you may need to use something like the 'when_present' method after clicking the link before you first start to interact with it. eg if all you want to do is click the link to open it, and then close it, you'd do something like this
browser.link(:text => 'Security Statement').click
browser.div(:class => 'spread_close').when_present.click

Resources