Send text to Text Field - selenium

How to send Text in text area field using geb & Spock?
Using just Selenium & the sendKeys I am able to send the text.
But unable to implement using geb spock.
this[field] = value - Not working
element.sendKeys(""); - Working

You probably want to look into the use of Geb Modules, particularly the Text Area module.
Taken from the documentation:
Given the html…
<html>
<body>
<textarea name="language"/>
</body>
</html>
It can be used this way…
def textarea = $(name: "language").module(Textarea)
textarea.text = "Groovy"
assert textarea.text == "Groovy"

<html>
<body>
<textarea name="language" id = "id1"/>
</body>
</html>
=====================================================
//content definition
textarea = { $(#id1") }
//updating value
textarea.value("your value")
OR
textarea << "your value"

Related

python splinter comparing unicode elementlist with string

I want to get all the anchor tag text from an iframe named "ListFirst". I'm trying to iterate text and comparing each with the string 'AGENT-WIN3E64 ' that I want to click.But the comparison I made here e['text'] == u'AGENT-WIN3E64 ' becomes false event though the strings are same. Please help.
Here is my code:
with iframe12.get_iframe('ListFirst') as iframe1231:
anchorList=iframe1231.find_by_tag('a')
for e in anchorList:
if e['text'] == u'AGENT-WIN3E64 ': #unicode string comparison
e.click()
break;
With the setup below I tried to recreate the situation you describe. The .py script below seems to find the anchor just fine though.
index.html,
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe name="mainframe" src="iframe1.html"></iframe>
</body>
</html>
iframe1.html,
<html>
<head></head>
<body>
<iframe name="childframe" src="iframe2.html"></frame>
</body>
</html>
iframe2.html,
<html>
<head></head>
<body>
AGENT-WIN3E64
b
c
d
e
</body>
</html>
test.py
from splinter import Browser
browser = Browser('firefox', wait_time=10)
browser.visit("http://localhost:8000/index.html")
# get mainframe
with browser.get_iframe('mainframe') as mainframe:
# get childframe
with mainframe.get_iframe('childframe') as childframe:
anchorList = childframe.find_by_tag('a')
for e in anchorList:
if e['text'] == u'AGENT-WIN3E64 ': #unicode string comparison
print "found anchor"
e.click()
break;
This outputs,
found anchor
But note that you could also find the anchor directly using xpath,
anchor = childframe.find_by_xpath("//a[text() = 'AGENT-WIN3E64 ']")

C# Selenium Webdriver (Firefox) iFrame does not allow text to be entered via sendKeys

I'm using latest Selenium Firefox (2.53.0)
Previously code was working when performing the following
1) Finding the iFrame by Xpath iframe class
IWebElement detailFrame = `Driver_Lib.Instance.FindElement(By.XPath("//iframe[#class='cke_wysiwyg_frame cke_reset']"));`
2) Switching to that frame by
Driver_Lib.Instance.SwitchTo().Frame(detailFrame);
3) finding the p tag within the iFrame by
IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("p"));
4) Inserting a simple string to the iframe text box
freeText.SendKeys("this is some text");
5) switching from the iFrame back to the main contentwindow by
Driver_Lib.Instance.SwitchTo().DefaultContent();
Here is the code part from the application
<iframe class="cke_wysiwyg_frame cke_reset" frameborder="0" src="" style="width: 100%; height: 100%;" title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor" aria-describedby="cke_61" tabindex="0" allowtransparency="true">
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title data-cke-title="Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor">Rich Text Editor, ctl00_ctl00_MainContentPlaceHolder_PageContent_mlcEditor_CKEditor</title>
<style data-cke-temp="1">
<link href="https://myUrl/contents.css" rel="stylesheet" type="text/css">
<style data-cke-temp="1">
</head>
<body class="cke_editable cke_editable_themed cke_contents_ltr cke_show_borders" contenteditable="true" spellcheck="false">
<p>
<br _moz_editor_bogus_node="TRUE">
</p>
</body>
</html>
</iframe>
The test I am running is a simple one, open up that page, insert some text, save.
It not inserting the text into the iFrame. I am totally puzzled as to why.
Has anyone else found this issue at all?
Many thanks
I have removed the exception, this was a redHerring.
the iFrame can not have text entered into it
hi all I've found the solution:~ here is the summary of what was happening:
1) The iFrame was being located by xPath.
2) the SwitchTo() method used placed focus in the detailFrame instance of IWebElement
3) What was not happening was the p tag could not be located as it was contained withing a CSS Body Class that.
The solution was staring me in the face the whole time! so simple!!
I did this:
IWebElement detailFrame = Driver_Lib.Instance.FindElement(By.XPath("//iframe[#class='cke_wysiwyg_frame cke_reset']"));
Driver_Lib.Instance.SwitchTo().Frame(detailFrame);
IWebElement freeText = Driver_Lib.Instance.FindElement(By.TagName("body"));
freeText.SendKeys("This is a free text question created by Automation Smoke Test");
Driver_Lib.Instance.SwitchTo().DefaultContent();
So as you see, simply locating the 1st instance of the body tag!

VB.net Can you read the text in a certain Div

I was wondering if you read text in a certain div so when the html code says:
<html>
<head>
</head>
<body>
<div id="Main">SomeText</div>
<div id="Text">Welcome to my website</div>
</body>
</html>
i only want to see 'Welcome to my website' in the textbox 1.
is there anyone who knows how i can do that?
any help would be much appreciated.
Mark your div with runat="server":
<div id="TextDiv" runat="server">Welcome to my website</div>
then access the text in VB.NET code:
TextDiv.InnerHtml
I would recommend the HTML Agility pack hosted on codeplex at http://htmlagilitypack.codeplex.com/. With it you can connect to a HTML source, load the HTML into an reasonably friendly navigator and use XML type queries to traverse and manipulate the HTML.
I would use HtmlAgilityPack, then it's easy as:
Dim html = System.IO.File.ReadAllText("path")
Dim doc = New HtmlAgilityPack.HtmlDocument()
doc.LoadHtml(html)
Dim welcomeDiv = doc.GetElementbyId("Text")
Me.TextBox1.Text = welcomeDiv.InnerText

pass form data to a new window

I'm trying to figure out how to pass form data collected from sql database to a new window. The idea is when the user click 'Rediger' (edit), that a new small window will open up with the current data and an input field for the user to change the data, and then hit the save button for the data to be written to the database. Then the window must close and the original page being updated with the new data. Is this possible? Can anyone please help me with this? Thank you.
Check out the page here: http://kristoff.it/onlinecoaching/coach/
Here is my dummy code:
<!DOCTYPE html>
<html>
<head>
<script>
function getValue()
  {
var txtfield=document.getElementById(this.id);
//alert(txtfield.innerHTML);
newWindow.document.write(txtfield.innerHTML);
return newWindow;
//windowsize(640, 480)
  }
</script>
</head>
<body>
<form method="POST" id="submitform">
<label id="name">John Smith</label><input type="button" id="button" onclick="getValue()" value="Edit">
<br>
<label id="title">Director</label><input type="button" id="button" onclick="getValue()" value="Edit">
</form>
</body>
</html>
You'll need some AJAX for this.
First follow this discussion, to be able to detect when the windows was closed.
Then make an ajaxRequest like this:
$.ajax({
url: "someUrlWhereYouCanFindTheUpdatedRecords.html",
cache: false
}).done(function( html ) {
//Some code that updates your webpage
});
Note that this code is using JQuery
Good luck!

Difference between innerhtml and outerhtml in cocoa WebView

I am using cocoa webview for rich text editing in my application. Just confused with innerHtml and outerHtml method avaiable in webkit.
Can anyone explain what is the difference between
[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerHTML];
AND
[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerText];
innerHTML is a property of a DOM element that represents the HTML
inside the element, i.e. between the opening and closing tags. It has
been widely copied, however implementations vary (probably because it
has no published standard[1]) particularly in how they treat element
attributes.
outerHTML is similar to innerHTML, it is an element property that
includes the opening an closing tags as well as the content. It
hasn't been as widely copied as innerHTML so it remains more-or-less
IE only.
<p id="pid">welcome</p>
innerHTML of element "pid" == welcome
outerHTML of element "pid" == <p id="pid">welcome</p>
and whereAs
innerText The textual content of the container.
outerText Same as innerText when accessed for read; replaces the whole element when assigned a new value.
<p id="pid">welcome</p>
innerText of element "pid" == welcome
outerText of element "pid" == welcome
Suppose we have a page loaded to webview with html
<html>
<head><title>Your Title</title></head>
<body>
<h1>Heading</h1>
<p id="para" >hi <b>Your_Name</b></p>
</body>
<html>
NOW.
[(DOMHTMLElement *)[[webView mainFrame] DOMDocument] documentElement]
will returen the DOMHTMLElement "html" and
outerHTML will return the complete html as
<html>
<head><title>Your Title</title></head>
<body>
<h1>Heading</hi>
<p id="para">hi <b>Your_Name</b></p>
</body>
<html>
outerText will return html as
Heading
hi Your_Name
for example if we take example of p tag in this case
outerHTML will return - <p id="para">hi <b>Your_Name</b></p>
outerText will return - hi Your_Name
innerHTML will return - hi <b>Your_Name</b>
innerText will return - hi Your_Name
i have explained it with the help of example where definition for these 4 terms already explained in the answer below.
<!DOCTYPE html>
<html>
<head>
<title>innerHTML and outerHTML | Javascript Usages</title>
</head>
<body>
<div id="replace">REPLACE By inner or outer HTML</div>
<script>
userwant = "inner";
userwant = "outer";
if (userwant = "inner") {
document.querySelector("#replace").innerHTML;
// this will remove just message: 'REPLACE By inner or outer HTML' //
} else if (userwant = "outer") {
document.querySelector("#replace").outerHTML;
// this will remove all element <div> ~ </div> by the message: 'REPLACE By inner or outer HTML' //
};
</script>
</body>
</html>