how to invoke onclick function in html from vb.net or C# - vb.net

I am trying to invoke the onclick function in an html page that displays content. I am using the httpwebreqest control and not a browser control. I have traced the function and tried to find the link it calls but looking at the code below I tried inserting the link into the browser with the main url but it does not work.
<div style="position:relative;" id="column_container">
<a href="#" onclick="
if (! loading_next_page) {
loading_next_page = true;
$('loading_recs_spinner').style.visibility = 'visible';
**new Ajax.Request('/recommendations?directory=non-profit&page=**' + next_page, {
onComplete: function(transport) {
if (200 == transport.status){
$('column_container').insert({ bottom: transport.responseText });
loading_next_page = false;
$('loading_recs_spinner').style.visibility = 'hidden';
next_page += 1;
if (transport.responseText.blank()) $('show_more_recs').hide();
}
}
});
}
return false;
Any ideas would be deeply appreciated.

Thanks anyone who has viewed...but I resolved the issue. The link after the ajax request was actually correct and it just was not showing anything in the browser but the source contains all the links I need.

Related

Response.Redirect not changing URL

After clicking an element on my webpage, I get the expected behavior from Response.Redirect in the trace, the break point on the expected page gets hit and proceeds to process normally. However when I'd expect the new page to be loaded, the display in the browser is not changed. It looks and behaves like the click brought you back to the same page.
I've moved the redirect call out of a try-catch block, and have tried different combinations of true/false as the second parameter with HttpContext...CompleteRequest()
What might prevent a page from being loaded after a call from Response.Redirect and the Page_Load sub completes?
Edit:
The site uses css and javascript to create a hoverable dropdown menu containing self referencing links, see below. I have tried using Chrome's dev tools to see what the network was processing. As far as I can tell from reading the Network Tab the click was creating the correct call; status 200, type xhr. xhr was the only thing that I found odd, but it looks like this is simply a reference to ajax? This leaves me in the same position. I am telling the site to redirect to new url, and I see the network take a request for that url, but the url in the address bar doesn't change; not the displayed page.
$(document).on('click','.navigation', function () {
loadItems($(this).attr('id'), $(this).attr('itemName'));
return false;
}
);
var loadItems = function (id, itemName) {
var editInfor =
{
"method": "getChildItems",
"id": id
};
$.ajax
(
{
type: "POST",
url: $.url,
dataType: "json",
data: JSON.stringify(editInfor),
success: function (jsonReply) {
$("#chkEnabled").attr('checked', jsonReply.enabled)
if (jsonReply.method == 'getChildItems') {
$("#childrens").html('');
var html = '<table>'
if (jsonReply.successfull) {
$.each(jsonReply.children, function (i, item) {
html += '<tr><td><span class="children">' + item.text + '</span></td><td><a class="moveItemUp btn" href="#" id="moveItemUp' + item.id + '">Move Up <i class="icon-circle-arrow-up"></i></a> <a class="moveItemDown btn" href="#" id="moveItemDown' + item.id + '">Move Down <i class="icon-circle-arrow-down"></i></a></td><td>Remove</td></tr>'
});
}
html += '</table>'
$($.childrens).html(html);
}
}
}
);
Please try this:
$.mobile.changePage( "/Exmaple.aspx", {
transition: "pop"
});

Getting the text of first <p> tag and check for successful login in an automation test script in Mocha and Selenium

I am having an automated testing script which I am trying to run using mocha on selenium environment.
The script first logs in, then checks the text of the all <p> tag.
If the text of any of the <p> tag matches the phrase ""Welcome to the admin page!"" then the login attempt will be considered successful. Else it's a failed attempt.
I want to change the code. Instead of iterating through all the tags, I just need to check with the first tag. How can I do that?
I want to record the details, whether the attempt is successful or failed one.
My code is given below.
var assert = require('assert');
var test = require('selenium-webdriver/testing');
var webdriver = require('selenium-webdriver');
var By = webdriver.By;
var until = webdriver.until;
var equals = webdriver.equals;
test.describe('TrackRevenue Test', function()
{
test.it('should work', function()
{
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.phantomjs())
.build();
var loginFlag = 0;
var baseUrl = 'http://saswatr3.ouh.co/login';
var expectedTitle = "Track Revenue";
var successMessage = "Welcome to the admin page!";
driver.get(baseUrl);
driver.getTitle().then(function(title)
{
if(expectedTitle === title)
{
console.log("Verification Successful - The correct title is displayed on the web page.");
}
else
{
console.log("Verification Failed - An incorrect title is displayed on the web page.");
}
});
driver.findElement(By.id('username')).sendKeys('saswat#matrixnmedia.com');
driver.findElement(By.id('password')).sendKeys('DarkPrince2012');
driver.findElement(By.id('_submit')).click();
driver.wait(until.titleIs('Track Revenue'), 1000);
driver.findElements(By.tagName('p')).then(function (pTag)
{
pTag.forEach(function(p) //I am iterating through all the <p>. I need to get only the first <p>
{
p.getText().then(function(text)
{
if(text.toLowerCase() === successMessage.toLowerCase())
{
loginFlag = 1;
}
//done(); //mocha async callback
});
});
if(loginFlag ==1)
console.log("Login Successful");
else
console.log("Login Unsuccessful");
});
driver.quit();
});
});
The html section of the <p> section having "Welcome to the admin page!"
<div class="wrapper wrapper-content animated fadeIn">
<div class="row">
<div class="col-centered col-xs-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>Links</h5>
<div class="ibox-tools"> </div>
</div>
<div class="ibox-content">
<p>Welcome to the admin page!</p>
<p>Please use the menu on the left</p>
</div>
</div>
</div>
</div>
</div>
PS.
I need some more modification in the code. In any case, if the login fails, then the login page has div which displays the text : "Invalid credentials."
The html of the section is like this:
<div class="text-danger text-danger-orange">Invalid credentials.</div>
I want to have a check script which detects this section as well.
EDIT:
When I am putting this piece of script, then my script runs fine:
driver.findElements(By.xpath("//p[contains(text(), 'Welcome to the admin page!')]")).then(function()
{
loginFlag = 1;
if(loginFlag ==1)
console.log("Login Successful");
else
console.log("Login Unsuccessful");
});
But when I am putting this piece of script, I am getting an
Type Error: Undefined is not a function
if(driver.findElements(By.xpath("//p[contains(text(), 'Welcome to the admin page!')]")).size() != 0)
{
loginFlag = 1;
}
else
{
//"Welcome to the admin page" not found
if(driver.findElements(By.xpath("//div[contains(text(), 'Invalid Credentials!')]")).size() != 0)
{
//do what you have to do if "Invalid credentials" is found
}
else
{
// "Invalid credentials not found"
}
}
You could make your life easier with using XPATH. For example:
if(driver.findElements(By.xpath("//* [text()[contains(.,'Welcome to the admin page!')]]")).size() != 0){
//do what you have to do if "Welcome to the admin page" is found
}else{
//"Welcome to the admin page" not found
if(driver.findElements(By.xpath("//* [text()[contains(.,'Invalid credentials')]]")).size() != 0){
//do what you have to do if "Invalid credentials" is found
}else{
// "Invalid credentials not found"
}
}
I hope this helps.
EDIT:
As you wish a little elaboration:
With xpath you can simply just search for the desired text which should occur on your page. If you just want to look for the string "Welcome to the admin page" or "Invalid credentials" regardless of the position on the page you can easily search a text by:
//* [text()[contains(.,'<your string text here>')]]
It checks if the getText() method of a node contains the given text.
If you want to check the whole page if there is a result you can use findElements because it will return all found WebElements. If there is nothing found with the given xpath it return an empty "array" with size 0. So if you use
driver.findElements(By.xpath("//* [text()[contains(.,'Welcome to the admin page!')]]")).size() != 0
you can check if the method has found an element with the desired text.
That is all, the other stuff is just simple if/else.. you can use the above mentioned xpath and function as you like. So instead of iterating trough ALL you <p> tags you can simple just use the above mentioned xpath.
EDIT2:
with mocha you could try doing something like:
driver.findElements(By.xpath("//p[contains(text(), 'Welcome to the admin page!')]")).then(function(elements_arr)
{
if(elements_arr.length > 0){
//your element got found
console.log("Login Successful");
}else{
//your element was not found
console.log("Login Unsuccessful");
driver.findElements(By.xpath("//div[contains(text(), 'Invalid Credentials!')]")).then(function(elements_arr2)
{
if(elements_arr2.length > 0){
//your element invalid credentials got found
console.log("Login Unsuccessful, div invalid credentials found");
}else{
//your element was not found
console.log("Login Unsuccessful, div invalid credentials not found");
}
});
}
});

Google Script for Uploading File Not Working

I wrote a script for uploading files to my Google Drive using the Google Script. I deployed it as a WebApp but it's not working and I don't know why. The button just gets stuck on "Subiendo..." and never changes anything inside my Drive. I'm sure I gave the script all the permissions and I already tried to see what's happening on my own without any sucess. Can you maybe help me find what should I do? I post the code here:
Code.gs
function doGet() {
return HtmlService.createHtmlOutputFromFile('main').setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function serverFunc(theForm) {
try{
var folder_name = "publicaciones";
var folder,folders = DriveApp.getFoldersByName(folder_name);
if(folders.hasNext()){
folder = folders.next();
}else{
folder = DriveApp.createFolder(folder_name);
}
Logger.log("TheForm", theForm == null);
var blob = theForm.theFile;
Logger.log("Blob!", blob == null);
var file = folder.createFile(blob);
Logger.log("File:", file.getName());
return "Archivo subido exitosamente: " + file.getUrl();
} catch(error){
Logger.log("error: ", error.toString());
return error.toString();
}
}
** main.html **
<div>
<form id="myForm">
<input type="file" name="theFile">
<input type="hidden" name="anExample">
<br>
<input type="button" value="Subir Archivo" onclick="this.value='Subiendo...';
google.script.run.withSuccessHandler(fileUploaded).serverFunc(this.parentNode);
return false;">
</form>
</div>
<div id="output">
</div>
<script>
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
I'd appreaciate any help or pointers you can give me. Thanks a lot!
Looks like there is a bug currently that Google is working on. I found a possible fix:
Change your input tag to this:
<input type="button" value="Subir Archivo" onclick="callServerCode()"/>
Add a function to the <script> tag:
<script>
function callServerCode() {
var formToSend = document.getElementById('myForm');
google.script.run
.withSuccessHandler(fileUploaded)
.serverFunc(formToSend);
};
function fileUploaded(status) {
document.getElementById('myForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
Note that inside the new function, it gets the form using var formToSend = document.getElementById('myForm');
And change IFRAME to NATIVE.
It's a doc issue needs to fix with Google when using SandBoxMode=IFRAME currently. See here. I've tested it works by swapping IFRAME to NATIVE. You can simply do it:
function doGet() {
return HtmlService.createHtmlOutputFromFile('main');
}
Google has turned of NATIVE for SandBoxMode. It is now set to IFRAME only.
See here

How do I display invalid form Dijits inside closed TitlePanes?

I have a large Dijit-based form with many Dijits in collapsible TitlePanes.
When the form validates, any invalid items hidden inside closed TitlePanes (obviously) cannot be seen. So it appears as though the form is just dead and won't submit, though, unbeknownst to the user, there's actually an error hidden in a closed TitlePane which is preventing the form processing.
What's the solution here? Is there an easy way to simply open all TitlePanes containing Dijits that are in an error state?
If validation is done by following, it will work:-
function validateForm() {
var myform = dijit.byId("myform");
myform.connectChildren();
var isValid = myform.validate();
var errorFields = dojo.query(".dijitError");
errorFields.forEach(fieldnode){
var titlePane = getParentTitlePane(fieldnode);
//write a method getParentTitlePane to find the pane to which this field belongs
if(titlePane) {
titlePane.set('open',true);
}
}
return isValid;
}
function getParentTitlePane(fieldnode) {
var titlePane;
//dijitTitlePane is the class of TitlePane widget
while(fieldnode && fieldnode.className!="dijitTitlePane") {
fieldnode= fieldnode.parentNode;
}
if(fieldnode) {
mynode = dijit.getEnclosingWidget(fieldnode);
}
return titlePane;
}
Lets say if the following is the HTML and we call the above validateForm on submit of form.
<form id="myform" data-dojo-type="dijit/form/Form" onSubmit="validateForm();">
......
</form>
Here's what I ended up doing (I'm not great with Javascript, so this might sucked, but it works -- suggestions for improvement are appreciated):
function openTitlePanes(form) {
// Iterate through the child widgets of the form
dijit.registry.findWidgets(document.getElementById(form.id)).forEach(function(item) {
// Is this a title pane?
if (item.baseClass == 'dijitTitlePane') {
// Iterate the children of this title pane
dijit.registry.findWidgets(document.getElementById(item.id)).forEach(function(child) {
// Does this child have a validator, and -- if so -- is it valid?
if (!(typeof child.isValid === 'undefined') && !child.isValid()) {
// It's not valid, make sure the title pane is open
item.set('open', true);
}
});
}
});
}

Disqus Plugin Explanation of Dynamic Tags

So I am using the Disqus Plugin v2.65. I am trying to edit the dsq-global-toolbar at the top of the Disqus comments.
The following tags are in disqus-comment-system/comments.php
<div id="disqus_thread">
<?php if (!get_option('disqus_disable_ssr')): ?>
<?php
// if (is_file(TEMPLATEPATH . '/comments.php')) {
// include(TEMPLATEPATH . '/comments.php');
// }
?>
<div id="dsq-content">
<ul id="dsq-comments">
however on my site there are mulitple tags (the disqus-global-toolbar div) that seem to be dynamically appended between the dsq-content div and the dsq-comments ul. Where is this coming from and where can I edit this? Any help would be greatly appreciated.
I think it is coming somewhere around line 3140 in disqus.js
You can use this code to wait for the document to finish loading completely then do your changes (client side):
$(document).ready(function() {
window.disqus_no_style = true;
$.getScript('http://sitename.disqus.com/embed.js', function() {
var loader = setInterval(function() {
if($('#disqus_thread').html().length) {
clearInterval(loader);
disqusReady();
}
}, 1000);
});
function disqusReady() {
//whatever you can imagine
}
});
window.diqus_no_style can be deleted as well as the $.getsript wrapper.
Is that what you are looking for?
Something like this (use livequery instead of live):
function disqusReady() {
$('#dsq-global-toolbar').livequery(function() {
//$(this) will refer to object
});
}
Not sure what plug-in you're talking about, but if it's WordPress, I've done the same thing. Modify wp-content/plug-ins/disqus-comment-system/comments.php by adding an event handler for 'afterRender' (fires when the content ready in the DOM, but still hidden), eg. around line 70:
config.callbacks.afterRender.push(myFunctionToModifyDisqusOutput);