Unable to find element when html document is inside an iframe - c#

<div class="reporting-graph-zone">
<input id="ctl00_m_g_a3080099_ed02_44e3_afe2_e6b89d1a2cee_ctl00_hiCulture" name="ctl00$m$g_a3080099_ed02_44e3_afe2_e6b89d1a2cee$ctl00$hiCulture" value="culture=en-US" type="hidden">
<iframe src="/PL/__LI_Partners/FederationMetadata/WIF.axd?ReturnUrl=%2frdPage.aspx%3frdReport%3dSingleDashboard%26culture%3den-US" style="">
<!DOCTYPE html>
<html id="yui_3_1_1487760521746_220" class="yui3-js-enabled" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:rdxslextension="urn:rdXslExtension" style="cursor: auto;">
<head>
<body id="yui_3_1_1487760521746_219" onload="rdBodyLoad()">
<div id="yui_3_1_1487760521746_369" class="yui3-widget rdquicktip yui3-widget-positioned rdquicktip-hidden" style="left: 0px; top: 0px;">
<form id="yui_3_1_1487760521746_218" name="rdForm" method="POST">
<table id="rdRows-1" class="rdDashboardPanelContainer" style="width:100%;" cellspacing="0">
<tbody id="yui_3_1_1487760521746_215">,
<tr id="rdDashboardMenu">
I am unable to find element "rdDashboardMenu" when html document is inside an iframe.
Could anyone help me out?

You should first select frame using below code:
driver.switchTo().frame(0);
After switching frame select element

Related

<br> tag issue in webbrowser

When I try to add a <br> tag after table and open it using winforms control WebBrowser.
<!DOCTYPE HTML><html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" align="left" width="100%"> <tbody>
<tr>
<td style="background:#ffb900;padding:5pt 2pt 5pt 2pt"></td>
<td width="100%" cellpadding="7px 6px 7px 15px" style="background:#fff8e5;padding:5pt 4pt 5pt 12pt;word-wrap:break-word">
<div style="color:#222222;"><span style="color:#222; font-weight:bold;">Caution:</span> Test caution here.
</div>
</td>
</tr>
</tbody>
</table>
<br>
<div>
<p>Test string here.</p>
</div>
</body>
</html>
It seems that it doesn't insert single line breaks in the text.
But it works in Edge and Chrome.
Why?
I know there are some workarounds to handle this issue, such as "add doube <br> after table"
</table>
<br>
<br>
<div>
or remove align="left"
<table border="0" cellspacing="0" cellpadding="0" width="100%">
However,is there any way to solve this problem once and for all? Instead of manually modifying each html file.
You should add a meta-tag that specifies the emulation mode, setting it to Internet Explorer 11 (the latest version available in the System of IE):
<meta http-equiv="X-UA-Compatible" content="IE=edge">
which gives you the expected behavior.
You can make a simple procedure that batch-adds this line right after <head> in your files.
If possible, probably better migrate to WebView2 to have the Edge-Chromium experience
See: Introduction to Microsoft Edge WebView2
If you cannot change HTML content, you can set the browser emulation to a higher IE version, like IE11 Edge mode in code. For example when loading the form, before setting the browser content:
using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
#"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
true))
{
var app = System.IO.Path.GetFileName(Application.ExecutablePath);
key.SetValue(app, 11001, Microsoft.Win32.RegistryValueKind.DWord);
key.Close();
}
For more information: How can I get the WebBrowser control to show modern contents?

get the iframe element in C#

I'm trying to get the id of the second iframe which is iframe2 in the codebehind to add some css styling. This is my html:
<body>
<form id="Form1" method="post" runat="server">
<table id="Table1">
<tr>
<td>
<iframe id="iframe1">
</iframe>
<uc1 id="uc1"></uc1>
</td>
</tr>
<tr>
<td>
<asp:Panel id="Panel">
</asp:Panel>
<uc1 id="uc2">
</uc1>
</td>
<td>
<iframe id="iframe2">
</iframe>
</td>
</tr>
</table>
</form>
</body>
For some reason I'm not able to get the iframe id in C#. How can I do that please?
Accessing the Iframe
Ensure that you add the runat="server" attribute to the <iframe>:
<iframe id="iframe2" runat="server"></iframe>
This will enable to to access it in your code-behind via the FindControl() method:
// Access your iframe
var iframe = FindControl("iframe2");
iframe.Style.Add("border", "2px solid red");
Or directly by using its assigned id:
iframe2.Style.Add("border", "2px solid red");
Regarding Styling
You mention that you are explicitly trying to style this element. If that is the case, you should likely be using CSS as opposed to setting inline styles on the <iframe> element itself.
For instance, you could apply styles as such to target that element:
<style type='text/css'>
#iframe {
/* Place your styles here (i.e. border: 4px solid red, etc.) */
}
</style>
It's worth noting that actually styling an <iframe> is going to only style the element itself, as the content that is rendered within it is essentially "sandboxed" within the element and won't be affected by some of the assigned styles.
Change the IFrame to have runat="server" you can then get to it on the server side.
<iframe ID="MyIframe" src="" runat="server"></iframe>
You can set set items in C#.
MyIframe.Attributes["src"] = Page.ResolveClientUrl("~/ThisOtherPage.aspx");
MyIframe.Attributes.Add("style", "cursor:pointer;");

Offset div element in Asp.net c#

Hi guys so i have a div slider element im trying to put in, but however i cannot seem to offset it at all my code is this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="StyleSheet.css" rel="stylesheet" />
</asp:ContentPlaceHolder>
<style type="text/css">
.auto-style2 {
width: 277px;
height: 150px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="Navbar">
<div class="Log">
<ul>
<li>Login</li>
<li>Register</li>
</ul>
</div>
</div>
<div class="Header">
<%-- <div id="boxtest">
<input id="Textbox" type="text" name="test"/>
</div> --%><img alt="gmaa" class="auto-style2" src="GMAA%20Logo%20Large%20Resized.png" />
<div class="nav">
<ul>
<li>Parents
</li>
<li>Providers
</li>
<li>About Us
</li>
<li>Faqs
</li>
<li>Applicants
</li>
</ul>
</div>
</div>
<div class="slider">
<img src="GMG%20Logo%20Large%20slider.jpg" border="0" alt="GMG"/>
<img src="GMAA%20Logo%20Large%20slider.png" border="0" alt="GMAA" />
<img src="GMRC%20Logo%20Large%20Slider.png" border="0" alt="GMRC"/>
</div>
</form>
</div>
</body>
</html>
now from my css it seems that everything should work as i moved an element that was inside of a div earlier but now its just not working at all?, does anyone have any tips, also here is the css for the slider element:
div.slider {
width:1000px;
height:541px;
overflow:hidden;
margin:auto;
left:-50px;
}
Simply put,... in order to position a div within its parent, make the parent element position:relative;
<div style="position:relative; height:500px; width:100%;">
<div style="position:absolute; left: 60px; top:60px; width:10px; height:10px;">
absolute
</div>
</div>
Next... why not look into JS library which supports this out of the box.?

facebook share a page with a photo

When I click 'Share', then it opens facebook share page in a new tab. I want to show temp.jpg in left bar in this page. How to do this?
test.aspx
<div id="page-wrap">
<!-- AnythingSlider #1 -->
<ul id="slider1" style="width: 778px; height: 452px; background:#fff;">
<li>
<div style="float: left; padding-right: 35px; padding-left:50px;">
<img src="../../img/temp.jpg" style="width: 264px;
height: 377px; border: none;" />
<uc:DownloadControl ID="DownloadControl1" runat="server" PageParameters="1" />
</div>
</li>
<li>
<uc:DownloadControl ID="DownloadControl2" runat="server" PageParameters="2" />
...
DownloadControl.ascx
<div style="float: left">
<a class="icerik" id="facebookShare" runat="server" target="_blank">
<img border="0" src="images/facebook.jpg" alt="Resorts"
title="Hotels & Resortss" /> Share </a>
DownloadControl.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
facebookShare.HRef = "http://www.facebook.com/sharer.php?u=http://www.test.com/test.aspx";
}
If you want to add custom information about your page while sharing with sharer.php, you must place additional open graph meta tags in the head of your page. For this example, test.com/test.aspx contains these tags:
<head>
<meta property="og:title" content="Test" />
<meta property="og:url" content="http://www.test.com/test.aspx" />
<meta property="og:image" content="http://www.test.com/img/temp.jpg" />
// other meta tags
</head>
More information about Open Graph protocol is here

Master Page More has more than one content

just now when i was created my master page it gives me this error. The page has one or more asp content that do not correspond withasp content place holder.
What is wrong with my master page? Here is my code of master page. Thank you.
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs"
Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Master</title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.style1
{
height: 63px;
}
.style3
{
height: 101px;
font-size: xx-large;
font-weight: 700;
font-family: Tahoma;
text-align: center;
color: #FFFFFF;
}
.style6
{
width: 146px;
height: 592px;
}
.style7
{
width: 897px;
height: 592px;
}
.style8
{
height: 592px;
}
.style9
{
font-size: small;
height: 101px;
border-left-color: #808080;
border-right-color: #C0C0C0;
border-top-color: #808080;
border-bottom-color: #C0C0C0;
background-color: #996633;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%; height: 623px; margin-bottom: 0px;">
<tr>
<td bgcolor="#996633" class="style3" colspan="3">
Malaysia Car Booking System<br />
<span class="style9">Your satisfaction is our Priority</span></td>
</tr>
<tr>
<td bgcolor="#CC6600" class="style6">
</td>
<td bgcolor="#FF9900" class="style7" style="vertical-align: top">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</td>
<td bgcolor="#CC6600" class="style8">
</td>
</tr>
<tr>
<td bgcolor="#996633" class="style1" colspan="3">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
What's wrong is that you have a Content tag in your content page that doesn't have a corresponding ContentPlaceHolder tag in the master page.
The only ContentPlaceHolder tag in the master page is in the head tag. It is quite uncommon to not have any in the body tag, as it makes it hard to introduce any body content from the content page. You have a PlaceHolder tag in the body that you perhaps meant to be a ContentPlaceHolder tag?
It would appear that your page has <asp:content> tags which do not correspond to <asp:ContentPlaceHolder> controls in your MasterPage.
For this type of solution, master pages never support comments in the format <!-- -->
This could be causing your error.
I got the same error when I created a very simple master page and let visual studio create a normal page based on that master page. After running the website, the error message disappeared. It seemed like the error message was based on the old master page and that visual studio used the changed master page only for verification once the website was actually run. Strange :-(
You need to include runat = "server" in title tag most of the time it solve the problem

Categories

Resources