Not able to identify the element in a page.It gives null.I want to identify the element in the Iframe (textbox) .I used selenium webdriver to click on the element,but it is not able to identify the element
1) My HTML Code is as shown bellow
<html>
<head>
<body>
<iframe id="iframeOne">
</iframe>
</body>
</head>
</html>
2. I used javascript to identify the textbox like document.getElementById('textbox').
But it return null.
3.I even Tried using selenium webdriver
IWebElement ClickElement = Wait.Until((d) => webDriver.FindElement(By.Id(parameter1))); It gives object reference error
ClickElement.Click();
You cannot put html inside an iframe tag. it is to load another page inside the curent page. and your input tag should caontain the type of the control. and check the HTML validation errors.
The html code you put inside the iframe tag will be loaded and visible if and only if the browser does not support iframe tag. So probably never, unless you're using older Netscape navigator or IE 4.
Add src attribute to the iframe pointing to the url you want to load. Then you can access elements inside this way:
var frame = document.getElementById('iframeOne');
var frameDocument = frame.contentDocument;
var element = frameDocument.getElementById('xxxx');
There's one thing to take into account, though: accesing contentDocument when iframe's src is cross-domain might not work as expected.
Related
I'm trying to write automated test case for a website, which is built using Classic ASP. Each web page (when viewed in the browser) is actually created using multiple ASP files, each of which takes a panel in the overall web page. When trying to use Selenium WebDriver, I can see elements in the main content, but cannot find the elements in the "included ASP files".
For example, the content of the navigation panel is coming from an ASP file; this is achieved by doing something like this...
navPanel.Body.Nav.Location.href = "navi.asp"
Although the content of the navi.asp page shows up when viewed in browser, I'm not able to get its contents using:
driver.FindElements(By.CssSelector("*"))
Could anyone please let me know how I can find the elements that are defined in the "included" asp file?
Here is additional info - the summary of html source as viewed in browser is as follows - as you can see below, there are multiple elements and by default the WebDriver seems to be picking up the elements of the last occurrence of the tag i.e, contents of the "Content" frame. But, I want to access the elements in "Nav" Frame. How can I do a switch between these frames. I tried using driver.SwitchTo().Frame("Nav") but it didn't work obviously because this frame is not visible from within "Content" frame.
<html>
<head></head>
<frameset name="Body">
<html>
<frame name="**Nav**"></frame>
<html>
<form id="**form1**"></form>
</html>
</frame>
<frame name="**Content**">
<html>
</html>
</frame>
</html>
</frameset>
</html>
It doesn't matter which language is the web page built with, you can use the browser to see what CSS Selector to use...
using Chrome (You can do similar things in different browsers too):
right click on the element that you are interested and press "Inspect element" then go to the Elements tab and right click on the html tag of that element and select "Copy CSS path" and that will copy the proper CSS selector to your clip board.
Look at the picture below:
I'm trying to get to this element: //*[#id="table-matches"]/table on this page: http://www.oddsportal.com/matches/soccer/20140221/
I want to get the table that contains matches. Table starts under Kick off time tab. The element I'm looking for is 'table class=" table-main"' and it is inside the element 'div id="table-matches" style="display: block;"'
I tried getting this document with HtmlAgilityPack in C# and I can find 'div' element, but it says that it doesn't have any child nodes (there should be a table child node). If I try to get the table, the result is null. Here is the code:
var webGet = new HtmlWeb();
var document = webGet.Load("http://www.oddsportal.com/matches/soccer/20140221/");
var div = document.DocumentNode.SelectNodes("//div[#id='table-matches']");
var table = document.DocumentNode.SelectNodes("//*[#id='table-matches']/table");
var table2 = document.DocumentNode.SelectNodes("//table");
So, div variable contains the div element (but it has no child nodes), table variable is null, even table2 variable contains 4 elements, but none of them are desired table.
I figured there is a problem with HtmlAgilityPack and tried to get the whole web page with Python. So I got the whole HTML document in a text file and searched the text file and I can find div element but it is empty. There is no table element inside. Why is that? Why can I see table element in chrome or internet explorer, but when I download html there is no such element?
Here is the python code:
url = urllib.urlopen("http://www.oddsportal.com/matches/")
document = url.read()
htmlOddsPortal = open("htmlOddsPortal.txt", "w")
htmlOddsPortal.write(document)
Here is the element in the final text document:
<div id="table-matches"></div> <!-- END PAGE BODY -->
Table is loaded with JavaScript (probably with AJAX) so you won't get it with webGet.Load(). You only get HTML that server returns in response.
You can check this if you (in Chrome) open Console (F12), click on Settings and check Disable JavaScript, then refresh page. You will see blank content.
I had same problem, but I worked in java, and I have used HTMLUnit to solve this. Probably there is similar tool for C#, or you can check if HtmlAgilityPack is able to do asynchronous call or something like WebBrowser component.
I need to write a page, can use PHP or .NET, that will display the unmodified html for an element of another page.
The other page may not have valid HTML, but we want it to be returned unmodified. We will not be selecting based on the invalid elements, but will select their parent element and need them returned unmodified.
An example HTML page that my page will be fetching:
<body>
<div>
<p>test1</p>
<br>
<p>test2
<p>test3</p>
</div>
</body>
So far everything I have tried attempts to fix the HTML, it makes the br in the example self closing and the second paragraph tags gets closed.
Is there anything out there that can do this?
Thanks!
Please can somebody explain how I can open up an ASPX page that is in my solution in a Kendo UI Window and get any values that I need?
What I want is to open a Kendo window with my own ASPX page which will pass an ID through to the main view after a template has been selected in the Kendo Window.
This demo shows how to load a remote page into the contents of a Window by using the content property:
window.kendoWindow({
content: "myPage.aspx"
});
Though by default it expects just HTML that it will inject into your page, so the result should not contain <html> <head> and <body> tags. However at that point the markup is just insterted into the page, so any JavaScript can directly communicate with the "parent" because they are all the same page.
You could also specify the iframe option
window.kendoWindow({
content: "myPage.aspx",
iframe: true
});
which will make the window contents an <iframe> instead of injecting it into the page.
I think your contents then could specify the <html> <head> and <body> tags just like a normal page, but now your JavaScript would have to do something different to pass a value back to the parent. That is back in the realm of normal JS, not Kendo. If I remember correctly, you can call a function in your iframe's parent by calling:
window.parent.myFunction("some value");
I have a JavaScript code which links to survey poll page. When I am embedding the JavaScript code in normal aspx page (without master page), I am getting the survey normally without any issues, but when I am embedding the same code in page which uses master page, I am getting blank page.
This way doesn't work: http://gyazo.com/27f38b5b04897cf0b17747eab05cf746
This way works: http://gyazo.com/c69d3b95afe4a0070cd09834e479a97f
Update
Using <script src='<%=ResolveClientUrl("~/Survey/xlaabsolute.asp?p=1")%>' type="text/javascript" /> renders the poll correctly but the button for voting doesn't do any postback http://gyazo.com/b39fcaa8de3438c8c2a625e3816ba4be.
I can see the content http://gyazo.com/b39fcaa8de3438c8c2a625e3816ba4be
Chances are it's how the script is referenced.
You're using a relative position in your src attribute which could potentially change if it's not in a location that allows Survery/... to be found. Maybe change it to /Survey/... so it always locates the file based on the root path and not where the document currently resides?
You can also make your script tag runat="Server" and reference the script using traditional ASP relative links: src="~/Survey/..." so it resolves correctly.
The way to resolve the issue and make it work regardless of where the control is being used is to use ResolveClientUrl as so:
<script src='<%=ResolveClientUrl("~/Survey/your_script.js")%>' type="text/javascript" />