Input field is filled, but content is not saved using Selenium IDE - selenium

Using Selenium IDE, I'm able to fill an input field (using "type" command), but when I "save" the value, this value is lost. Doing the same by hand, everything works fine.
Any hint to solve this issue? I've already tried using typeKeys command.
The code inside the target page is:
<!-- language-all: lang-html -->
<div id="editDiv" class="editDialog">
<table cellspacing="0" width="100%">
<tbody>
<tr>
<td width="25%" style="">period</td>
<td align="right" width="25%" style="padding: 6px;">
<input id="period" type="text" onblur="changeValue(this.id, this.value, undefined)">
<br>
<label>da 0 a 9</label>
</td>
</tr>
</tbody>
</table>
<table cellspacing="0" width="100%">
<input type="button" value="Save" onclick="applyChanges()">
<input type="button" value="Cancel" onclick="removeEditDialog(false)">
</div>
To help more on this issue:
function changeValue(id, value, paramPos) {
var par = tempGlobalParams[id] ? tempGlobalParams[id] : tempGlobalPaintingsParams[paramPos][id];
if(checkRules(id, value, paramPos)){
par.custom = value;
}

Related

Element not found Exception in Selenium

I am trying to sendKeys to the fields in an inline popup. company_name, contact_surname and contact_first_name. There are no iframes. I tried windowhandler also, but that did not work. Here is my code snippet and Please find the HTML code below::
driver.findElement(By.xpath("//input[#name='company_name']")).sendKeys("Ginger Bread");
driver.findElement(By.name("contact_first_name")).sendKeys("Ingrid");
driver.findElement(By.name("contact_surname")).sendKeys("Cumberbridge");
HTML Code:
<div id="ibox_content" style="overflow: auto; height: 322px;"><div id="quickCreateForm" style="background:silver; padding:4px; border:1px solid white; width:95%;">
<form>
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tbody><tr><td colspan="2" align="center">
<input type="button" value="Create" class="button" onclick="return quickCreate(this, true); ">
<input type="button" value="Close" class="button" onclick="iBox.hide();">
</td></tr>
<tr><td align="right" valign="top"><strong>Company:</strong></td>
<td align="left" valign="top" nowrap="">
<input type="text" name="company_name" value="" size="15" maxlength="120">
</td></tr>
<tr><td align="right" valign="top"><strong>First Name:</strong></td>
<td align="left" valign="top">
<input type="text" name="contact_first_name" value="" size="15" maxlength="120">
</td></tr>
<tr><td align="right" valign="top"><strong>Last Name:</strong></td>
<td align="left" valign="top">
<input type="text" name="contact_surname" value="" size="15" maxlength="120">
</td></tr>
</tbody></table>
</form>
</div></div>
Try using CSS Selector
driver.findElement(By.CssSelector("input[name=company_name]")).sendKeys("Ginger Bread");
driver.findElement(By.CssSelector("input[name=contact_first_name]")).sendKeys("Ingrid");
driver.findElement(By.CssSelector("input[name=contact_surname]")).sendKeys("Cumberbridge");
The below xpath should help you:
//div[#id='ibox_content' and contains(#style,'height')]//input[#name="company_name"]
Try with the xpath given below:
driver.findElement(By.xpath("//input[contains(#name,'company_na')]")).sendKeys("Ginger Bread");
You can use the following Locator Strategies to invoke sendKeys() to the desired fields:
Company:
driver.findElement(By.xpath("//div[#id='quickCreateForm']/form//td/strong[contains(.,'Company')]//following::td[1]/input")).sendKeys("Ginger Bread");
First Name:
driver.findElement(By.xpath("//div[#id='quickCreateForm']/form//td/strong[contains(.,'First Name')]//following::td[1]/input")).sendKeys("Ingrid");
Last Name:
driver.findElement(By.xpath("//div[#id='quickCreateForm']/form//td/strong[contains(.,'Last Name')]//following::td[1]/input")).sendKeys("Cumberbridge");
It seems you are sending keys before actual element is getting loaded, so
You need to give explicit wait before you are trying to sendkeys to it,
WebElement element = new WebDriverWait(Driver,30).until(ExpectedConditions.elementToBeClickable(By.name("company_name")));
or you may use this,
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
then call,
driver.findElement(By.xpath("//input[contains(#name,'company_name')]")).sendKeys("Ginger Bread");

Automating using Selenium

I am trying to find the text from the Select Elements "[New List]". The HTML code behind this is :
<div id="pageBody">
<div class="grid">
<div class="col_12 bgColor column">
<form method="POST" action="pickListEdit.cfm" name="formMain" id="formMain">
<input type="hidden" id="usrAction" name="usrAction" value="NONE"/>
<input type="hidden" id="listtype" name="listtype" value="ACCTS"/>
<input type="hidden" id="listmodified" name="listmodified" value="0"/>
<table cellpadding="0" cellspacing="0" border="0" width="620">
<tbody>
<tr class="alt first last">
<td>
<table cellpadding="0" cellspacing="0" border="0" width="360">
<tbody>
<tr class="alt first">
<td width="150" align="right" class="critH2">
<td height="1" align="left">
<select name="listkey" size="1" onchange="formSubmit('GET');"class="selectfont">
<option value="0">[New List]</option>
</select>
</td>
</tr>
<tr class="alt last">
</tbody>
</table>
</td>
<td width="10"/>
<td width="10"/>
<td valign="top">
</tr>
</tbody>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="600">
</form>
</div>
</div>
</div>
</div>
</body>
The C# code that I am using is :
var AccPic = Driver.Instance.FindElement(By.ClassName("selectfont"));
var selectelement = new SelectElement(AccPic);
selectelement.SelectByText(AP);
The problem is it is unable to find the field name. What I need to do is find the element [New List] and select it. Can someone please help.
Assuming it's the only option tag on the page:
var newList = Driver.Instance.FindElement(By.TagName("option"));
var selectedElement = new SelectElement(newlist);

How to select radio button in selenium web driver java using text of nearby element in XPath

I need to select radion button with id="optProfile" in 7th tr using text "Internet Users" in td/font tag. I am using below code but it is not working and selecting radio button from 1st tr row. Can anyone help
<html>
<head>
<body onmousedown="infCheckMouseDown(event);" onkeydown="infCheckDownKey(event);" onbeforeunload="INFIEExit();" onload="INFsetInitialFocus();window_onload();CreateScriptingFrames();">
<form action="PEINFCommon.ASP?WCI=Genericcreen&WCE=GenericEvent" onsubmit="return false" name="Genericcreen" method="post">
<table class="TopLevelTable" align="center" width="100%" border="0">
<tbody>
<tr>
<td width="100%">
<table width="100%" border="0">
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<td width="100%">
<div align="center">
<center>
<table width="98%" cellspacing="0" cellpadding="0" border="0" cols="1">
<tbody>
<tr align="center">
<td align="left">
<table width="100%">
<tbody>
<tr>
<tr>
<tr>
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<tr height="">
<td width="5%">
<input id="optProfile" type="Radio" callfunction="" value="" onblur="ResetScript(this);return true;" onfocus="HighlightScript(this);" onclick="" name="" size="11">
<font class="fLabel"></font>
<br>
<input id="hidCurrentProfile" type="hidden" onblur="ResetScript(this);" onfocus="HighlightScript(this);" value="N" callfunction="" size="11" name="/Root/ACORD/InsuranceSvcRs/nk_ck_com.cc_FetchUserProfileRs/nk_ck_com.cc_SecurityDetails/nk_ck_com.cc_AvailableProfile[12]/nk_ck_com.cc_CurrentProfileInd">
<input id="hidProfile" type="hidden" onblur="ResetScript(this);" onfocus="HighlightScript(this);" value="RACINTER" callfunction="" size="11" name="/Root/ACORD/InsuranceSvcRs/nk_ck_com.cc_FetchUserProfileRs/nk_ck_com.cc_SecurityDetails/nk_ck_com.cc_AvailableProfile[12]/nk_ck_com.cc_ProfileCd">
</td>
<td>
<font class="">Internet Users</font>
</td>
</tr>
<tr height="">
<tr height="">
<tr height="">
<tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</center>
</div>
</td>
</tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
</frame>
<frame id="Script" scrolling="Yes" frameborder="0" noresize="">
</frameset>
</html>
you need to use ancestor instead of preceding:
//font[text()='Internet Users']/ancestor::tr[1]/td/input[#type='Radio']
and it's also a better practice to tell which one of the tr-ancestors you want -> [1] - since you want the first direct ancestor
Is there a reason why you are not using the id of the radio button?
WebElement wElement = wDriver.findElement(By.Id("optProfile"));
You can use the following XPath
//tr[.//font[text()='Internet Users']]//input[#id='optProfile']
This xpath looks for the tr containing the font tag with text "Internet Users" and then navigates to the input tag with id = 'optProfile'
You can use preceding as below-
By.xpath("//font[contains(text(),'Internet Users')]/preceding::input[#id='optProfile']")
Thanks everyone here for your help. I really appreciate it.Its working with below code
WebElement trs = GlobalVar.wDriver.findElement(By.xpath("//font[text()='Internet Users']/ancestor::tr[1]"));
trs.findElement(By.id("optProfile")).click();
I would try something like this
List<WebElement> trs = driver.findElements(By.cssSelector("table > tr"));
for (WebElement tr : trs)
{
List<WebElement> fonts = tr.findElements(By.tagName("font"));
if (!fonts.isEmpty() && fonts.get(0).getText().trim().equals("Internet Users"))
{
tr.findElement(By.id("optProfile")).click();
break;
}
}
You didn't show the TABLE tag in the HTML snippet so you will likely need to be more specific in the initial CSS selector. Basically this code loops through the TRs looking for "Internet Users" in the FONT tag. Once it finds it, it click the radio button with id=optProfile.
If you will post the TABLE tag in the HTML snippet I can help with the CSS selector.
Edit 1: changed the code to address the case where some TRs don't contain FONT tags.

I want to extract a text string on the webpage which is written in the form of table, but I am getting null in return

WebElement e5 = d1.findElementByXPath("/html/body/div[1]/div[3]/div/div[1]/form/div/div[1]/div/table/tbody/tr[4]/td[2]");
String a = e5.getText();
System.out.println(a);
_____________________________________________________________________________
I have used getText method. The data is stored in the table, so the strategy which I am making use of is that first of all i want to get to the location of that data using xPath funda and then I need to extract the data corresponding to that location. Can anyone suggest a better way to do so.Thanks in advance.
pls find below the html:
<div class="wrapper">
<form method="post" action="">
<input id="_csrf" type="hidden" value="psJdnI5AnxjGqT2knrZG" name="_csrf">
<div class="innercontainer">
<div class="leftpanel">
<h2>MY ACCOUNT</h2>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<td>
<strong>Membership ID:</strong>
</td>
<td>2800000101</td>
</tr>
<tr>
<tr>
<tr> </tr>
<tr>
</tbody>
</table>
</div>
</div>
<div class="rightpanel">
</div>
</form>
</div>
html page added above. Kindly suggest some alternative
You need to clean up your Xpath, however this should help
WebElement tableText = driver.findElement(By.xpath("yourXpath"));
String actualText = tableText.getAttribute("textContent");
System.out.println(actualText)

Auto login form with Visual Basic

I need make an auto login form application with Visual Basic 10.0 for the following code:
</script>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<table cellpadding="0" cellspacing="0" border="0" height="100%">
<tr>
<td rowspan="10" width="50%" height="100%" background="images/bg1222.jpg" style="background-position:right top; background-repeat:repeat-y"></td>
<td rowspan="10" width="1" bgcolor="#000000"></td>
<td valign="top">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width=100%>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="778" height="153">
<param name="movie" value="images/hed2.swf">
<param name="quality" value="high">
<embed src="images/hed2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="778" height="153"></embed>
</object>
</td>
</tr>
</table>
</td>
<!--<td rowspan="10" width="0" bgcolor="#000000"></td>-->
<td rowspan="10" width="50%" height="100%" background="images/bg1223.jpg" style="background-position:left top; background-repeat:repeat-y"></td>
</tr>
<tr>
<td width="780" height="30" align="center" valign="bottom" background="images/footer.gif"></td>
</tr>
<tr>
<td height="583" valign="top" style="background-repeat:repeat-y;" >
<br><br><br><br><br><br><br>
<center>
<form action="/cse/login/login1_check.jsp" name="first" method="post">
<table width="25%" height="90" border="0" class='formtable1'>
<caption align="top">
<strong> User Login </strong>
<br>
</caption>
<tr>
</tr>
<tr>
<td width="24%" height="32">
<div align="right"> User ID: </div>
</td>
<td width="76%">
<label>
<input name="uid" type="text" >
</label>
</td>
</tr>
<tr>
<td height="43">
<div align="right"> Password: </div>
</td>
<td>
<label>
<input name="password" type="password" >
</label>
</td>
</tr>
</table>
<input type="submit" name="sub" value="Login">
</form>
</center>`enter code here`
Say username is user and password is pass.
It should be auto filled and clicked in the submit button. What would the code be for Visual Basic 10.0?
Try this:
If Not String.IsNullOrEmpty(My.Settings.Username) And Not String.IsNullOrEmpty(My.Settings.Password) Then
TxtUsername.Text = My.Settings.Username
TxtPassword.Text = My.Settings.Password
End If
You first need to take all the elements that you want to interact to. If they have an ID, you don't need to search, simply get the element with:
Dim elem As HtmlElement = Webbrowser1.Document.GetElementById("myId")
If not, you need to search for yours, for example:
Dim inputs As New List(Of HtmlElement)(a.Document.GetElementsByTagName("input"))
For Each elem As HtmlElement In inputs
If elem.GetAttribute("name").Equals("uid") Then
'...
End If
Next
To set a value of a input:
elem.SetAttributte("value", passwordVar)
To click a clickable element (such a submit input):
elem.InvokeMember("submit")
Or:
elem.InvokeMember("click")