How to interact with second tab via javascript - javascript

So currently Im trying to make Google Chrome extension using Visual Studio Code and JavaScript. I havent worked with JS before. So I have this part right now, Im taking some info from the first page and then I open the second one and try to click button on it, but its still working only on the first one. Ive tried .focus and setTimeout but nothing works.
window.open("https://somesite");
setTimeout(1000)
document.querySelector(".submitButton").click()

JavaScript only works on page when you code it.
If you want to create javascript on new page - you need to write all code again.
On PAGE 2 button will not works , becuse JS is not shared on all pages. You needs to write again JS function to click that button

Related

Converting an HTML Java script to work with ASP.Net C#

Good day everyone,
I have been tasked with recreating a page that was originally written in HTML, to aspx.
I have successfully recreated the page and added additional functionality, but the main thing is it's suppose to run a java script once the submit button is hit.
I have the provided java, but don't really understand how to get it to work with my page.
I'm not even sure where to put the java code to begin with. The other examples online I couldn't make sense to what im trying to do. Please help.
Took a screen shot since it cuts out a lot of my code for some reason.
You can bind the submit button to a event and run the code inside the script in it.
Something similar to this:
$("#[YOUR_SUBMIT_ID_BUTTON]").on('click', function(e) {
e.preventDefault();
//Your JavaScript Code
});

ReadSpeaker broken webpage in Chrome

We're using ReadSpeaker component for the web.
We have a button for start to read, we call it to a function of Readspeaker called readpage()) the problem starts when we make click on this button the whole web it breaks, is as if the web changes to pdf file without CSS and the button disappear.
Know What is happen? Sorry for can't explain it well I don't know what'sh happen exactly.
Just find the solution!
http://hldev.readspeaker.com/?faq=how-can-i-prevent-javascript-from-breaking-when-readspeaker-is-active
If you have Javascript content inside the reading area these objects can break when ReadSpeaker is active.
This is because we add temporary HTML code to be able to highlight the content that is going to be read.

Embedded calendar stopped working

I am responsible for maintaining 2 websites. One is a Wordpress website that is just a list of events using Time.ly's All in One Event Calendar plugin. The other is a conventional built from scratch website using html.
The html website has had code that embedded the Wordpress calendar feed into it for several years, and it's always worked fine and I haven't had to do anything with it. Recently, it just stopped working. The calendar feed is just gone with no errors returned, no problems loading the site or anything. It looks as if somebody just deleted the code for it. However, the code is still there and is as follows:
<script class="ai1ec-widget-placeholder" data-widget="ai1ec_superwidget" data-action="stream" data-tag_ids="45">
(function(){var d=document,s=d.createElement('script'),
i='ai1ec-script';if(d.getElementById(i))return;s.async=1;
s.id=i;s.src='http://www.texascitycommunitycalendar.com/?ai1ec_js_widget';
d.getElementsByTagName('head')[0].appendChild(s);})();
</script>
Can anybody identify any obvious reason that that might have just stopped working?
I don't see a reason for that very last () pair in the script tag (just before the semicolon that is followed by the closing </script>tag. Try to erase it.

Chrome: Is it possible to create button combination to run custom javascript on page

I want to create a simple button combination, that when it's clicked it will run these javascript lines on the page:
document.getElementsByClassName("yt-uix-button-content")[18].click();
document.getElementsByClassName("addto-playlist-item")[1].click();
Is it possible, or is there extension that could help me do this?Thank you for your time.
I happened upon this question when looking into a similar issue. What I ended up doing is a bookmark-link with the custom-js as URL (has to start with javascript:) and then I just click it. Works like a charm. For your question, just add a new bookmark to your bookmark-panel and set the following as URL:
javascript:function hola(){ document.getElementsByClassName("yt-uix-button-content")[18].click(); document.getElementsByClassName("addto-playlist-item")[1].click(); } hola();

Selenium clicking button with no name or id

I've been struggling with trying to automate this page. After I login, I'm at this page where I'm supposed to click a button before I redirects me to the next page. The problem is that this button does not have a name or an ID which is making it very difficult to find this element. I've tried mechanize and splinter both. And finally tried selenium but that didn't help either. Really struggling with this. Just need to click this damn button! Any help would be really really appreciated. Love python and automation, but this time nothing seems to be working for me. Please find below a snapshot showing the the code shown when I click on "inspect element". Also, I can't type here the page source code as it is >300000 characters, so you can probably take a look at the page (you'll need to login which takes just 10 seconds). The page I'm referring to is right after you login - http://www.160by2.com/Index
[!Snapshot showing the code I get when I click "inspect element"
[]1
There is class name:
driver.findElement(By.className("da-sms-btn").
Also you can open application in Chrome and copy CSS or XPATH in browser:
Open application in Chrome
Inspect element
Right click on highlighted area
Copy CSS or XPATH
You can try first getting the form by the id, then getting the button by the class name:
wd.find_element_by_id("frmDashboard").find_element_by_class_name("da-sms-btn").click()
You can try to find the element through its xpath. Selenium does a good job of this:
webdriver.find_element_by_xpath("element xpath").click()
You can easily find the xpath by going to the inspect element sidebar on Chrome and right clicking on the element you want. The right click drop down menu should have an option "copy xpath".
I would write a cssSelector as follows and try that.
button[onclick*='aSMS']
Notice, I am doing a partial search with *
Thank you so much for your replies! I was actually able to make it work using splinter instead of selenium! Here's what I did-
1) I just executed the js which was being executed on the onclick event of the button.
jsstring="window.parent.openPage('SendSMS?id="+id+"', 'aSendSMS', 'aSMS', 'ulSMS')"
br.execute_script(jsstring)
2) Subsequently, I was faced with the problem that on the next page, everything was embedded inside iframe, and so find_by_name and all were not able to find elements. For that, splinter provides a nice method (Which is documented REALLY bad, so had to figure it out myself with help from stackoverflow)
with br.get_iframe('iframe_Name') as iframe:
iframe.fill("Element_to_fill_Name","Text_to_fill")
iframe.find_by_tag("TagName")[Index_number].fill("Text_To_Fill")
Worked out brilliantly! Thanks everyone :)

Categories