Automatically press a button from iframe - c#

I have a HTML page that have an iframe. This iframe has a button. Which is one of the possibile ways to press that button?
I tried with javascript, but I didn't solve it...
Thank you in advance!

hey you can try to find that button id and handle the click event..
it will look something like this.
$('#youriframeid').contents().find('#yourbuttonid').click(function(){});
EDIT
Your main html page containing iframe.
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.0.min.js" type="text/javascript"> </script>
<script>
$('#a').contents().find('#iframbtn').click(function(){alert("It Worked!")});
$('#a').contents().find('#iframbtn').trigger('click');
</script>
</head>
<iframe id="a" source="a.html">
</iframe>
</html>
Your second html page containing iframe mark up
<html>
<input type="button" id="iframbtn" value="clickme"/>
</html>

Try to use this:
$("#mainiframe").contents().find("someID").trigger("click");

Sample1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
function call(){
try{
document.frm.but.click();
}catch(e){
}
}
</script>
<BODY onload ="call()">
<iframe src="Sample2.html" name="frm" width=100 height=100 />
</BODY>
</HTML>
Sample2.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script>
function called(){
alert("---DONE--");
}
</script>
<BODY>
<input type="button" name="but" value="submit" id="but" width=60 height=60 onclick="called()" />
</BODY>
</HTML>
Hope this helps you.

Related

Korean utterances are not well mapping into GeneratePdf from html content

I am generating pdf from this HTML, and for achieving this I am using https://www.nrecosite.com/pdf_generator_net.aspx
This is the HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<p>Remarks</p>
<p>한국어 발언을 표시하는 테스트입니다</p>
</div>
</body>
</html>
and this the code for generating the pdf:
var pdfBytes = new
NReco.PdfGenerator.HtmlToPdfConverter().GeneratePdf(html);
and the result is this:
how can I generate the pdf with the correct Korean utterances?
Thanks

A section won't render in my ASP.NET MVC website with error: "the delegate type could not be inferred"

This is the layout code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<!-- theme meta -->
<meta name="theme-name" content="A Hopefull Life" />
</head>
<body>
<div>
#RenderBody()
</div>
<div>
#RenderSection ("myFAQ")
</div>
</body>
</html>
This is the code for the faq.cshtml:
#{
ViewData["Title"] = "FAQ";
Layout = "/Views/Shared/FAQLayout.cshtml";
}
#section myFAQ{
}
This is a simplified code of the entire website, I thought I did everything accordingly, but I got the error message. I thought it was the contents of the section causing the error (which was a few paragraphs) so I removed it but it wasn't the source.

Script tag not working ASP.NET core, webpack, typescript and knockout

I have a solution made up of the above technologies. I am using knockout components made up of .html and .ts files. When trying a simple <script> tag on the .html file, nothing happens.
The component is payment-details.html and the code is as simple as follows:
<h1>Payment details</h1>
<script type="text/javascript">
alert("test");
</script>
The underlying payment-details.ts is:
import * as ko from 'knockout';
class PaymentDetailsViewModel {
constructor() {
}
}
export default { viewModel: PaymentDetailsViewModel, template: require('./payment-details.html')};
and the _Layout.cshtml file is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>#ViewData["Title"] Contactless Check In</title>
<base href="~/" />
<environment exclude="Development">
<link rel="stylesheet" href="~/dist/site.css" asp-append-version="true" />
</environment>
</head>
<body>
#RenderBody()
<script src="~/dist/vendor.js" asp-append-version="true"></script>
#RenderSection("scripts", required: false)
</body>
</html>
I'm not sure what the issue is or where to start looking. There's something in the solution somewhere that is stopping script execution. Nor does it render in the html.
Thank you!

How can we detect web elements of a website built with react components which does not have html tag (to work with selenium C#)?

// Navigate to Account Managemnt window
Thread.Sleep(10000);
chrome_driver.FindElement(By.XPath("//*[#id='module-menu']/div/button")).Click();
Thread.Sleep(10000);
chrome_driver.FindElement(By.XPath("//*[#id='module-menu']/div/div/button[2]")).Click();
//*[#id="module-menu"]/div/div/button[2]
Thread.Sleep(20000);
IWebElement body = chrome_driver.FindElement(By.TagName("body"));
var result = chrome_driver.FindElement(By.TagName("body")).Text;
Console.WriteLine(result);
IWebElement Single_Acc_Add = chrome_driver.FindElement(By.XPath("//*[#id='single-add-button']/button/span"));
//chrome_driver.FindElement(By.LinkText("+ Add")).Click();
action.MoveToElement(Single_Acc_Add).Build().Perform();
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<link rel="manifest" href="/manifest.json">
<link rel="shortcut icon" href="/favicon.ico">
<title>PCR Universe</title>
<link href="/static/css/main.ed365ca1.css" rel="stylesheet">
</head>
<body>
<div
id="GLOBAL_INFO"
data-envvar="-siteminder"
data-clientname="universal-dashboard"
data-clientid="3027d708-26a2-4b63-a131-d672617f46f4"
data-domain="azurewebsites.net"
data-apienvvar="-siteminder"
data-apiname="universalwidgetservice"
data-apidomain="azurewebsites.net"
data-LOGINURL="https://universal-dashboard-siteminder.azurewebsites.net/authorize"
data-LOGOUTURL= './Logout.html'
data-ERRORPAGE= './LoginError.html'
data-ENCODEDCOOKIE= 'false'
data-USETOKENAUTH= 'false'
>
</div>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script type="text/javascript" src="/static/js/main.84c386bd.js"></script>
</body>
</html>
I am working with selenium and came across a website which is not created with java script but react elements, how can i detect IWebElement when there are no html tags. Not able to detect them with link Text as well.

jQueryMobile Datebox won't take a default date value - tried everything

I am trying to open a jQueryMobile datebox in a dialog mode. I am trying to set the datebox to a default value but it just won't take it for some reason. Here is my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>#PageData["Title"]</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<link rel="stylesheet" type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.css" />
<link rel="stylesheet" href="#Href("/Styles/theme/mysite.min.css")" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<script src="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.js"></script>
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/i8n/jquery.mobile.datebox.i8n.en.js"></script>
</head>
<body>
<script type="text/javascript">
$('document').ready(function(){
//Setting start date value on pageload
$('#myqdate').value('2012-01-14');
$('#myqdate').datebox('refresh');
}
</script>
<form name="shiftform" id="shiftform" action="#Href("~/Account/QChanges.cshtml")" method="post">
<div data-role="fieldcontain">
<label for="myqdate">Date:</label>
<input name="myqdate" id="myqdate" type="date" value="" data-role="datebox" data-options='{"mode": "flipbox", "forceInheritTheme": true, "defaultDate":"2012-01-14"}'>
</div>
<input type="submit" value="Get Queue"/>
</form>
</body>
</html>
I would really appreciate help from experts.
Thanks
This should do it:
$('#myqdate').trigger('datebox', {'method':'set', 'value':'2012-01-14', 'date':new Date('2012-01-14')})
It seems that you should be using the "defaultValue" property instead of the "defaultDate" that is in the data-options of your posted code. No need for the script block.
try closing your function:
$('document').ready(function(){
//Setting start date value on pageload
$('#myqdate').value('2012-01-14');
$('#myqdate').datebox('refresh');
}
)};

Categories