I'm trying to read an element from a dynamic website, but am facing a weird (at least to my poor understanding) issue.
Below is a snapshot from the Developer Tool from Chrome
I'm trying to read the innertText of the highlighted line (please note this is a dynamic website, so the "li id's"change).
When I'm firing document.querySelector("#\\31 60698c8-9d6c-492b-acf8-13b82467f873 > div > span.room-display-message-message") in the DevTools Console while highlighting the line as in the above snapshot the innerText is returned, but when I'm moving my selection higher up in the tree, e.g. to "iframe class = "trollbox-iframe" and then running the same script it returns "null".
This behavior also pops up when making the script more random like document.querySelector("* > div > span.room-display-message-message")
Am I getting crazy or is this normal and should I take another approach?
I'm asking this because I'm developing a tool in C# using a CEFSharp Chromium webbrowser to read contents of this website, but that's not relevant at the nmoment
OK, itr took me a few days, but I finally got what I wanted. For those interested here's my solution:
First thing is to add a CefSharp.WinForms.CefSettings to your browser element, being "--disable-web-security"
For calling this trollbox iframe I'm using below Javascript (I know it can be simplified, but hey...it works
var script2 = "function foo(){" +
"var re = /[^-a - zA - Z!, '?\s]/g;" +
"var messages = [];" +
"doc = document.getElementsByClassName('trollbox-container open')[0];" +
"ifrm = doc.getElementsByTagName('iframe')[0];" +
"docInside = ifrm.contentDocument ? ifrm.contentDocument : ifrm.contentWindow.document;" +
"docTag = docInside.getElementsByClassName('content small')[0];" +
"msgList = docTag.getElementsByClassName('message-list')[0];" +
"msgList_sender = msgList.getElementsByClassName('room-display-message-sender');" +
"msgList_message = msgList.getElementsByClassName('room-display-message-message');" +
"for (var i = 0; i < msgList_sender.length; i++)" +
" {" +
" var sender = msgList_sender[i].innerText;" +
" var message = msgList_message[i].innerText;" +
" messages.push(sender + ': ' + message);" +
" }" +
"return messages;" +
"}" +
"foo();";
Finally running this code
JavascriptResponse response = await browser1.EvaluateScriptAsync(script2);
returns me the information from the trollbox I wanted
Related
I have been attempting to code a button into my adobe PDF form using an article from quora. The goal is to click a button and it opens an email box with the "to", "subject line", "body" and the "PDF" attaching to the email without having to save the pdf somewhere locally on the clients computer.
These are the three different codes I have found and attempted to use. No matter what I do, I end up getting an "Unterminated String Literal" on line 3 where the body field starts. I have tried adding/removing everything I can think of. ;"'{{:.
Please help if you can! See code below.
var customSubject = this.getField("MyTextField").value;
var mailtoUrl = "mailto:email#email.com?subject=" + Information Form;
this.submitForm({Thank you for your considerate attention to the attached pdf. Let me know if you need anything.; further.
cURL: mailtoUrl, cSubmitAs: "PDF" });
var customSubject = this.getField("MyTextField").value;
var mailtoUrl = "mailto:email#email.com=" + Information Form;
this.submitForm({Thank you for your considerate attention to the attached pdf. Let me know if you need anything.
cURL: mailtoUrl, bPDF:true});
var cToAddr = "email#email.comm"
var cSubLine = "Information Form - " + this.getField(No1LastName) + ", " + this.getField(No2LastName) + "
var cBody = "Please find the attached Information Form. Thank you for your considerate attention to the attached."
this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});
I found that declaring a variable for the email portion worked. I was able to include custom to, cc, subject, and body, as well as attaching the PDF.
var customREmail = this.getField("ReqEmail").value;
var customAEmail = this.getField("AgyEmail").value;
var customAgency = this.getField("Agency").value;
var customLName = this.getField("Lease").value;
var customBAddr = this.getField("BldgAddr").value;
var customBCity = this.getField("BldgCity").value;
var mailtoUrl =
"mailto:XXX#XXX.XXX?cc=" +
customREmail +
"; " +
customAEmail +
"&subject=Compliance%20Request: " +
customAgency +
", " +
customLName +
" - " +
customBAddr +
", " +
customBCity +
"&body=Please review the attached request.%0A%0AThank you,%0A%0A";
this.submitForm({
cURL:mailtoUrl, cSubmitAs:"PDF", bPDF:true
});
DISCLAIMER: I'm new to Stack Overflow and I'm not a developer.
I work in IT and we are currently trying to take all of our paper/electronic forms and turn them into Google Forms. I am currently trying to write a script (see below) that will send an email to a specific person based on one of the answers. The good news is that the script works (woot!).
The problem that I'm having is that I get 2 - 3 of the exact email when I test it. It's especially bad in with my gmail account.
If the below code looks atrocious, I'm open to suggestions! Thanks in advance for the help!!
function myFunction() {
var form = FormApp.getActiveForm()
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
var work = itemResponses[3];
var problem = itemResponses[2].getResponse();
var location = itemResponses[4].getResponse();
var name = itemResponses[0].getResponse()
var sheetsLink = docs.google.com/sheetid
}
if (work.getResponse() === "Food Services") {
MailApp.sendEmail('mymail#gmail.com', 'Kitchen Maintenance', name + ' has a problem with ' + problem + ' in the kitchen at ' + location + '. More information for this request can be found at: ' + sheetsLink + '.');
} else {
MailApp.sendEmail('mymail#schoolacct', 'Maintenance', name + ' has a problem with ' + problem + ' at ' + location + '. More information for this request can be found at: ' + sheetsLink + '.');
}
}
It might be easier for you to get the form responses saved in a spreadsheet then tie the apps script to the spreadsheet with an on form submit trigger. This will allow you to have a record of all form responses in the spreadsheet and if anything goes wrong, you can always recheck. On the multiple emails sent, the multiple editors is the thing to check.
edit: Problem solved! I was modifying the page before it was loaded so the script didn't actually do anything. I fixed it now and it works. Thanks for the help, I'll have to chalk this one up to being new to jQuery and it's weirdness.
Long story short I'm trying to make a webpage that dynamically takes Article titles, thumbnail images, descriptions, and links to them, and creates a nicely formatted list on the page. I'm trying to accomplish this in jQuery and HTML5.
Here is the sample data that I'll be using to dynamically populate the page. For now formatting isn't important as I can do that later after it works at all.
<script>
var newsTitles = ["If It Ain't Broke, Fix It Anyways"];
var newsPics = ["images/thumbnail_small.png"];
var newsDescs = ["August 14th 2015<br/><b>If It Ain't Broke</b><br/>Author: Gill Yurick<br/><br/> Sometimes, a solution isn't the only one. So how do we justify changes to systems that don't need to be fixed or changed? I explore various systems from other successful card games and how their approaches to issues (be they successes or failures in the eyes of the deisgners) can help us create EC."];
var newsLinks = ["it_aint_broke-gill_popson.html"];
var newsIndex = 0;
var newsMax = 1;
The section of code where I'm trying to use the contents of the arrays above to dynamically fill elements.
<td style="height:500px;width:480px;background-color:#FFF7D7;padding:20px" colspan=2 id="article">
<h1>Articles</h1>
<!-- the column for each news peice add an element with the thumbnail, the title and teh desc -->
<script>
for(i = 0; i < newsMax; i++) {
$("#articleList").append("<h3 href="" newsLinks[i] + "">" + newsTitles[i] + "</h3>", "<img src=""newsPics[i] + "">","<p>" + newsDesc[i] + "</p>", ); $("div").append("hello");
}
</script>
<div id="articleList">
HELLO
</div>
</td>
Here is what it ends up looking like, I can post more info if needed as I am aware this may not be clear enough to fully explain my problem but I am unable to determine that. Thank you in advance.
try this
for(i = 0; i < newsMax; i++) {
$("#articleList").append("<h3 href=""+ newsLinks[i] + "">" + newsTitles[i] + "</h3>, <img src=""+newsPics[i] + "">, <p>" + newsDescs[i] + "</p>" ); $("div").append("hello");
}
Concatation issue + typo for newsDescs
The following string is invalid html and is missing a +
"<h3 href="" newsLinks[i] + "">"
You need to use proper quotes for html attributes, not "e;
Try
"<h3 href='" + newsLinks[i] + "'>"
OR
"<h3 href=\"" + newsLinks[i] + "\">" // `\` used to escape same type quote
Personally I prefer opening/closing html strings with single quotes but either will work
Note tht you should be getting a syntax error thrown in dev tools console which would have helped you locate problems
for(i = 0; i < newsMax; i++) {
$("#articleList").append("<h3 href='" + newsLinks[i] + "'>" + newsTitles[i] + "</h3>");
$("#articleList").append("<img src='" + newsPics[i] + "'>","<p>" + newsDesc[i] + "</p>" );
}
i'm trying use a Java plugin to print to raw print to a ticket printer from a browser. I've written a test program in HTML and Javascript which is working ok, but now i'm trying to transfer the code to a php script for printing tickets in a bigger app. I'm gettting this kind of error in firefox debug whenever i call a function from the app. "TypeError: qz.findPrinter is not a function".
I changed the extension on the original test program to .php from .html and i'm recieving error there too now.
Any functions from the the java begin with "qz."
Here's the plugin for reference
https://code.google.com/p/jzebra/wiki/TutorialWebApplet
I figure it's something i don't know about php as it works ok as a .html file but I've included the whole script anyway. The php is running from xampp.
Thank you for you time.
<html>
<head><title>Receipt Test</title>
<script type="text/javascript" src="js/deployJava.js"></script>
<script type="text/javascript">
deployQZ();
function deployQZ() {
var attributes = {id: "qz", code:'qz.PrintApplet.class',
archive:'qz-print.jar', width:1, height:1};
var parameters = {jnlp_href: 'qz-print_jnlp.jnlp',
cache_option:'plugin', disable_logging:'false',
initial_focus:'false'};
if (deployJava.versionCheck("1.7+") == true) {}
else if (deployJava.versionCheck("1.6+") == true) {
attributes['archive'] = 'jre6/qz-print.jar';
parameters['jnlp_href'] = 'jre6/qz-print_jnlp.jnlp';
}
deployJava.runApplet(attributes, parameters, '1.5');
}
function countSpace(product, price, section) {
var spaceNeeded = (section - product.length - price.toString().length);
var spaces = "";
for(i=0; i < spaceNeeded; i++) {
spaces += " ";
}
return (product + spaces + price);
}
function findPrinter() {
// Searches for locally installed printer with "zebra" in the name
qz.findPrinter("zebra");
// Hint: Carriage Return = \r, New Line = \n, Escape Double Quotes= \"
var ticketTime = new Date();
var singleLine = "\n------------------------------------------\n";
var doubleLine = "\n==========================================\n";
var product = ["Mirdan Tuzlama", "Suckuklu Pide" ];
var price = [8.00, 8.00];
var prodCharLength = 37;
var finCharLength = 42;
var subTotal = {name:"Subtotal", value:0};
for(i=0;i<product.length;i++) {
subTotal.value += price[i];
}
var tax = {name:"Tax", value:((20/100)*subTotal.value)};
var total = {name:"Total", value:(subTotal.value-tax.value)};
var ticketEnd = " Thank You\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
var productSec = "";
tax.value = 0 - tax.value;
for(j=0;j<product.length;j++) {
var priceloop = price[i];
productSec += (" - 1 " + countSpace(product[j], price[j],prodCharLength));
if (j<=(product.length-2)){
productSec += "\n"
}
}
qz.append("\nDate:" + ticketTime.getDate() + "/"
+ (ticketTime.getMonth()+1) + "/"
+ ticketTime.getFullYear()
+ "\nTime:" + ticketTime.getHours() + ":"
+ ticketTime.getMinutes()
+ "\nTable: B10\nTicket No:2"
//+ singleLine + " - 1 " + product1 +" 8.00\n - 1 " + product1 +" 8:00"
+ singleLine + productSec
+ doubleLine + countSpace(subTotal.name, subTotal.value,finCharLength)
+ '\n' + countSpace(tax.name, tax.value,finCharLength)
+ '\n' + countSpace(total.name, total.value,finCharLength)
+ doubleLine + ticketEnd);
qz.print();
}
</script>
<body>
<input type="button" onClick="findPrinter()" value="Print ESCP" /><br />
</body>
"TypeError: qz.findPrinter is not a function"
In QZ "Tray" 1.9 (desktop Application), qz.findPrinter(...) is defined as a preemptive function, created by qz-websocket.js and must be included in your project to be exposed. If you didn't include qz-websocket.js, this message will occur.
In QZ "Print" 1.9 (Java Applet) and older, qz.findPRinter(...) was exposed through a Java Applet using Java LiveConnect calls, so this was a sign the applet did not load. If your applet did not load properly, this message will occur.
Note: 1.9 was capable of behaving as both a desktop application AND a Java applet.
Deprecation warning: 1.9 and older are EOL. QZ Tray 2.0 and higher, the API has changed significantly. A migration guide is available.
I finally got my back-end to create the wheel codes from the checked taxonomies in the add custom post admin area.
Now, I want to add that tire code to the wheel_type taxonomy.
The below code ran great, until I added the if statement under //Add code to Taxonomy
Now nothing is working, but I get nothing in the error console.
I figure it must be a stupid syntax mistake - can anyone help me out?
Or am I missing something else?
jQuery('#replace').click(function(){
//get tire code and name
var code = jQuery('input[name="tire_code"]').val();
var name = jQuery('input[name="tire_name"]').val();
var bname = jQuery('input[name="tire_bname"]').val();
alert(code + " + " + name + " + " + bname);
//get tire brand
var tirebran = jQuery('#tire_brandchecklist').find(":checked").parent('label').text();
tirebran = jQuery.trim( tirebran );
//Add code to Taxonomy
if( term_exists( code, wheel_type ){
continue;
}
else
{
wp_insert_term( code, wheel_type );
}
//update title
var title = code + ' : ' + name + ' tires';
if(tirebran!=''){
title += ' with ' + bname + ' letters';
}
jQuery('input[name="post_title"]').focus().val(title);
});
//-->
</script>
unless i've misunderstood your question, you're trying to call wordpress methods via javascript.
term_exists() and wp_insert_term() are PHP methods within the wordpress code, not accessible directly via Javascript (unless you have written interfaces to them).
continue doesn't make any sense there; just check for !term_exists... and call wp_insert_term when it doesn't exist.
if (!term_exists(code, wheel_type)) {
wp_insert_term(code, wheel_type);
}
The continue statement is for continuing loops from the top of the loop; it does not stand on its own.