Finding the idNumber element from this below HTML code - java

<div id="rightContent" style="display: inline-block; width: 700px; vertical-align: top;">
<div>
<h1><em class="SomethingHeading">Something</em></h1>
</div>
<div class="content scaffold-list" role="main">
<h1>Search</h1>
<form action="/SomethingArchiveUI/search/search" method="post">
<table>
<tbody>
<tr>
<td>ID/Registration Number:</td>
<td>
<**input type="text" name="idNumber" maxlength="20" value="" id="idNumber"**>
</td>
</tr>
<tr>
<td>Client Name:</td>
<td>
<input type="text" name="clientName" maxlength="50" value="" id="clientName">
</td>
</tr>
<tr>
<td>Client Surname:</td>
<td>
<input type="text" name="clientSurname" maxlength="50" value="" id="clientSurname">
</td>
</tr>
<tr>
<td colspan="2">
<input type="hidden" name="_dateRange"><input type="checkbox" name="dateRange" value="true" id="dateRange"><label for="dateRange"> Use date range?</label>
</td>
</tr>
<tr>
<td colspan="2"><p>From: <input type="text" name="fromDate" value="" maxlength="10" id="fromDate" class="hasDatepicker"> To: <input type="text" name="toDate" value="" maxlength="10" id="toDate" class="hasDatepicker"></p></td>
</tr>
</tbody>
</table>
<div style="display: inline;">
<div id="divSubmit">
<input type="submit" name="cmdSearch" class="buttons" value="Search" id="cmdSearch">
</div>
<div id="divBusy" style="display: none;">
Busy Searching...
</div>
</div>
</form>
<table id="customerIdentificationList" style="display: block;">
</table>
<div id="loadingMessage" style="display: none;">
Loading. Please wait.
</div>
</div>
</div>
I used this code below for logging into the Application, but similar code doesn't seem to work on this form above. I'm trying to find the 'idNumber' element:
driver.findElement(By.xpath("//*[#id='idnumber']")).sendKeys("Username");
driver.findElement(By.xpath("//*[#id=\'password\']")).sendKeys("Password");
driver.findElement(By.xpath("//*[#id=\'submit\']")).click();
The error i get is: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":
Looking forward to your responses.

Use : .//input[#id='idnumber']

Why not just use By.id()?
driver.findElement(By.id("idNumber"));

I don't know the reason why you can't use By.id() or By.xpath in this case. But you can try to find the input using text in previous td. I hope next code will help:
driver.findElement(By.xpath("//td[text()='ID/Registration Number:']/following-sibling::td/input")).sendKeys("Username");

Try using the below way -
First get the root element and keep it to a WebElement object. Then find for input element idNumber
WebElement elem = driver.findElement(By.cssSelector("#rightContent > div.content.scaffold-list > form"));
elem.findElement(By.id("idNumber")).sendKeys("Username");

Related

How to select a row using a text in dynamic web table using selenium in Java?

In my application my projects list grows dynamically in a table. I need to select a project using its name. Select button is in 2nd column and the project name is in 3rd column. How to open the project using its name?
<table class="ui celled definition sortable striped compact table" xpath="1">
<thead class="full-width">
<tr>
<th colspan="9">
<div role="combobox" aria-expanded="false" class="ui search selection dropdown per-page">
<input aria-autocomplete="list" autocomplete="off" class="search" tabindex="0" type="text" value=""/>
</div>
<a href="/project-setup">
<button class="ui orange big circular icon right floated button">
<i aria-hidden="true" class="plus icon"/>
</button>
</a>
</th>
</tr>
<tr>
<th class="select-delete-check-box">
<div class="ui fitted checkbox">
<input class="hidden" id="selectAll" readonly="" tabindex="0" type="checkbox" value=""/>
<label for="selectAll"/>
</div>
</th>
<th> Open </th>
<th>ID</th>
<th>Owner</th>
<th>Members</th>
<th>Created At</th>
<th>Last Updated</th>
</tr>
</thead>
<tbody>
<tr>
<td class="select-delete-check-box">
<div class="ui fitted checkbox">
<input class="hidden" id="5e992e2b14d2d67c91eb51c9" readonly="" tabindex="0" type="checkbox" value=""/>
<label for="5e992e2b14d2d67c91eb51c9"/>
</div>
</td>
<td class="collapsing">
<a href="/project-setup?id=5e992e2b14d2d67c91eb51c9">
<button class="ui green big circular icon right floated button">
<i aria-hidden="true" class="pencil icon"/>
</button>
</a>
</td>
<td>
<div class="step">
<div class="content">
<div class="title" style="font-size: 1.2em; font-weight: bold;">A</div>
<div class="description">
<span>
<i aria-hidden="true" class="blue globe icon"/>3,4</span>
<br>
<span>
<i aria-hidden="true" class="red map marker alternate icon"/> Poland</span>
</div>
</div>
</div>
</td>
<td>abc#abc.com</td>
<td/>
<td>17/04/2010, 09:48:51</td>
<td>17/04/2010, 09:48:51</td>
</tr>
<tr>
<td class="select-delete-check-box">
<div class="ui fitted checkbox">
<input class="hidden" id="5e97f0a0adba5850643c7202" readonly="" tabindex="0" type="checkbox" value=""/>
<label for="5e97f0a0adba5850643c7202"/>
</div>
</td>
<td class="collapsing">
<a href="/project-setup?id=52">
<button class="ui green big circular icon right floated button">
<i aria-hidden="true" class="pencil icon"/>
</button>
</a>
</td>
<td>
<div class="step">
<div class="content">
<div class="title" style="font-size: 1.2em; font-weight: bold;">B</div>
<div class="description">
<span>
<i aria-hidden="true" class="blue globe icon"/> 1,2</span>
<br>
<span>
<i aria-hidden="true" class="red map marker alternate icon"/> Tamil Nadu, India</span>
</div>
</div>
</div>
</td>
<td>abc#abc.com</td>
<td/>
<td>16/04/2010, 11:14:00</td>
<td>16/04/2010, 17:08:01</td>
</tr>
</tbody>
</table>
Try this:
WebElement table=driver.findElement(By.tagName("tbody"));
table.findElement(By.xpath("//div[#class='title' and contains(text(),'A')]/ancestor::td[1]/parent::tr/td[2]/a/button")).click();

How do I ensure that all fields are loaded on the page in selenium so that none are stale?

Problem
I have a PeopleSoft page that I am trying to test with the Selenium Web Driver for Java. However, I keep running into this error:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
I have read here, here, and here, as well as other Stack Overflow questions, and none of the answers are working for me.
Layout of the Page
The PeopleSoft page that I am testing is an I9 form, and the part I care about looks like this:
The corresponding HTML is really large and messy--as all PeopleSoft pages are--and it has in the middle of it, an iframe that wraps pretty much the entire page.
For reference, this JSFiddle has all of the HTML that is inside that iframe.
Here is the portion that corresponds to the sections in the above image:
<table role='presentation' border='0' id='ACE_width' cellpadding='0' cellspacing='0' class='PSPAGECONTAINER' cols='46' width='963'>
<!-- OMITTED -->
<tr>
<td height='16'></td>
<td colspan='19' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_LAST_NAMElbl'>
<label for='G_FORM_I9_G_LAST_NAME' id='G_FORM_I9_G_LAST_NAME_LBL' class='PSEDITBOXLABEL'>*Last Name (Family Name)</label>
</DIV>
</td>
<td colspan='9' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_FIRST_NAMElbl'>
<label for='G_FORM_I9_G_FIRST_NAME' id='G_FORM_I9_G_FIRST_NAME_LBL' class='PSEDITBOXLABEL'>*First Name (Given Name)</label>
</DIV>
</td>
<td colspan='3' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_MIDDLE_INITIALlbl'>
<label for='G_FORM_I9_G_MIDDLE_INITIAL' id='G_FORM_I9_G_MIDDLE_INITIAL_LBL' class='PSEDITBOXLABEL'>Middle Initial</label>
</DIV>
</td>
<td colspan='14' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_MAIDEN_NAMElbl'>
<label for='G_FORM_I9_G_MAIDEN_NAME' id='G_FORM_I9_G_MAIDEN_NAME_LBL' class='PSEDITBOXLABEL'>Other Last Names Used (if any)</label>
</DIV>
</td>
</tr>
<tr>
<td height='32' colspan='2'></td>
<td colspan='19' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_LAST_NAME'>
<input type='text' name='G_FORM_I9_G_LAST_NAME' id='G_FORM_I9_G_LAST_NAME' tabindex='43' value="Tiger" class='PSEDITBOX' style='width:232px; ' maxlength='30' onchange="addchg_win0(this);oChange_win0=this;" aria-required='true' />
</DIV>
</td>
<td colspan='9' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_FIRST_NAME'>
<input type='text' name='G_FORM_I9_G_FIRST_NAME' id='G_FORM_I9_G_FIRST_NAME' tabindex='44' value="Tony" class='PSEDITBOX' style='width:160px; ' maxlength='30' onchange="addchg_win0(this);oChange_win0=this;" aria-required='true' />
</DIV>
</td>
<td colspan='2' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_MIDDLE_INITIAL'>
<input type='text' name='G_FORM_I9_G_MIDDLE_INITIAL' id='G_FORM_I9_G_MIDDLE_INITIAL' tabindex='45' value="" class='PSEDITBOX' style='width:19px; ' maxlength='1' onchange="addchg_win0(this);return doEdits_win0(this,'','N','N','N','N','Y','N',0);"
/>
</DIV>
</td>
<td colspan='14' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_MAIDEN_NAME'>
<input type='text' name='G_FORM_I9_G_MAIDEN_NAME' id='G_FORM_I9_G_MAIDEN_NAME' tabindex='46' value="" class='PSEDITBOX' style='width:180px; ' maxlength='50' />
</DIV>
</td>
</tr>
<tr>
<td height='16'></td>
<td colspan='21' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_ADDRESSlbl'>
<label for='G_FORM_I9_G_ADDRESS' id='G_FORM_I9_G_ADDRESS_LBL' class='PSEDITBOXLABEL'>*Address (Street Number and Name)</label>
</DIV>
</td>
<td colspan='5' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_APARTMENT_NBRlbl'>
<label for='G_FORM_I9_G_APARTMENT_NBR' id='G_FORM_I9_G_APARTMENT_NBR_LBL' class='PSEDITBOXLABEL'>Apt. Number</label>
</DIV>
</td>
<td colspan='7' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_CITYlbl'>
<label for='G_FORM_I9_G_CITY' id='G_FORM_I9_G_CITY_LBL' class='PSEDITBOXLABEL'>*City or Town</label>
</DIV>
</td>
<td colspan='6' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_STATElbl'>
<label for='G_FORM_I9_G_STATE' id='G_FORM_I9_G_STATE_LBL' class='PSEDITBOXLABEL'>*State</label>
</DIV>
</td>
<td colspan='6' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_POSTALlbl'>
<label for='G_FORM_I9_G_POSTAL' id='G_FORM_I9_G_POSTAL_LBL' class='PSEDITBOXLABEL'>*Zip Code</label>
</DIV>
</td>
</tr>
<tr>
<td height='32' colspan='2'></td>
<td colspan='20' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_ADDRESS'>
<input type='text' name='G_FORM_I9_G_ADDRESS' id='G_FORM_I9_G_ADDRESS' tabindex='47' value="" class='PSEDITBOX' style='width:324px; ' maxlength='50' aria-required='true' />
</DIV>
</td>
<td colspan='6' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_APARTMENT_NBR'>
<input type='text' name='G_FORM_I9_G_APARTMENT_NBR' id='G_FORM_I9_G_APARTMENT_NBR' tabindex='48' value="" class='PSEDITBOX' style='width:81px; ' maxlength='10' />
</DIV>
</td>
<td colspan='8' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_CITY'>
<input type='text' name='G_FORM_I9_G_CITY' id='G_FORM_I9_G_CITY' tabindex='49' value="" class='PSEDITBOX' style='width:120px; ' maxlength='30' aria-required='true' />
</DIV>
</td>
<td colspan='5' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_STATE'>
<input type='text' name='G_FORM_I9_G_STATE' id='G_FORM_I9_G_STATE' tabindex='50' value="" class='PSEDITBOX' style='width:53px; ' maxlength='6' onchange="addchg_win0(this);oChange_win0=this;" aria-required='true' />
<a class='PSHYPERLINK' name='G_FORM_I9_G_STATE$prompt' id='G_FORM_I9_G_STATE$prompt' tabindex='51' href="javascript:pAction_win0(document.win0,'G_FORM_I9_G_STATE$prompt');">
<img src="/cs/ps/cache2/PT_PROMPT_LOOKUP_1.gif" alt='Look up State (Alt+5)' title='Look up State (Alt+5)' border='0' align='absmiddle' />
</a>
</DIV>
</td>
<td colspan='5' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_POSTAL'>
<input type='text' name='G_FORM_I9_G_POSTAL' id='G_FORM_I9_G_POSTAL' tabindex='52' value="" class='PSEDITBOX' style='width:80px; ' maxlength='12' onchange="addchg_win0(this);oChange_win0=this;" aria-required='true' />
</DIV>
</td>
</tr>
<tr>
<td height='16'></td>
<td colspan='9' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_BIRTHDATElbl'>
<label for='G_FORM_I9_G_BIRTHDATE' id='G_FORM_I9_G_BIRTHDATE_LBL' class='PSEDITBOXLABEL'>*Date of Birth (mm/dd/yyyy)</label>
</DIV>
</td>
<td colspan='13' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_SSNlbl'>
<label for='G_FORM_I9_G_SSN' id='G_FORM_I9_G_SSN_LBL' class='PSEDITBOXLABEL'>*U.S. Social Security Number</label>
</DIV>
</td>
<td colspan='14' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_EMAILIDlbl'>
<label for='G_FORM_I9_G_EMAILID' id='G_FORM_I9_G_EMAILID_LBL' class='PSEDITBOXLABEL'>Employee's E-mail Address</label>
</DIV>
</td>
<td colspan='9' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_PHONElbl'>
<label for='G_FORM_I9_G_PHONE' id='G_FORM_I9_G_PHONE_LBL' class='PSEDITBOXLABEL'>Employee's Telephone Number</label>
</DIV>
</td>
</tr>
<tr>
<td height='9' colspan='2'></td>
<td colspan='9' rowspan='2' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_BIRTHDATE'>
<input type='text' name='G_FORM_I9_G_BIRTHDATE' id='G_FORM_I9_G_BIRTHDATE' tabindex='53' value="05/05/1955" class='PSEDITBOX' style='width:71px; ' maxlength='10' onchange="addchg_win0(this);return doEdits_win0(this,'DMDY/450','N','N','N','N','N','N',0);"
onkeyup="if (isPromptKey(event))DatePrompt_win0('G_FORM_I9_G_BIRTHDATE','G_FORM_I9_G_BIRTHDATE','450',false);return false;" aria-required='true' />
<a class='PSHYPERLINK' name='G_FORM_I9_G_BIRTHDATE$prompt' id='G_FORM_I9_G_BIRTHDATE$prompt' tabindex='54' onfocus='doFocus_win0(this,true,false);' href="javascript:DatePrompt_win0('G_FORM_I9_G_BIRTHDATE','G_FORM_I9_G_BIRTHDATE$prompt','450',false);">
<img src="/cs/ps/cache2/PT_CALENDAR_1.gif" alt='Choose a date (Alt+5)' title='Choose a date (Alt+5)' border='0' align='absmiddle' />
</a>
</DIV>
</td>
<td colspan='6' rowspan='2' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_SSN'>
<input type='password' name='G_FORM_I9_G_SSN' id='G_FORM_I9_G_SSN' tabindex='55' value="888881125" class='PSEDITBOX' style='width:74px; ' maxlength='9' onchange="addchg_win0(this);oChange_win0=this;" aria-required='true' />
</DIV>
</td>
<td colspan='6'></td>
<td colspan='16' rowspan='2' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_EMAILID'>
<input type='text' name='G_FORM_I9_G_EMAILID' id='G_FORM_I9_G_EMAILID' tabindex='58' value="" class='PSEDITBOX' style='width:232px; ' maxlength='60' />
</DIV>
</td>
<td colspan='7' rowspan='2' nowrap='nowrap' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_PHONE'>
<input type='text' name='G_FORM_I9_G_PHONE' id='G_FORM_I9_G_PHONE' tabindex='59' value="" class='PSEDITBOX' style='width:179px; ' maxlength='24' onchange="addchg_win0(this);oChange_win0=this;" />
</DIV>
</td>
</tr>
<tr>
<td height='23' colspan='2'></td>
<td colspan='6' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_DRV_G_SSN'><span id='G_FORM_I9_DRV_G_SSN$span' onMouseOver="MOpopupObj_win0.StartPopup('win0divG_FORM_I9_DRV_G_SSN', 'G_FORM_I9_DRV_G_SSN_G_POPUP_SSN', 406, 90);" onMouseOut="MOpopupObj_win0.StopPopup(); " class='PSHYPERLINK' style='border-bottom:1px dashed black;padding-bottom:1px;display:inline-block;'><a name='G_FORM_I9_DRV_G_SSN' id='G_FORM_I9_DRV_G_SSN' ptlinktgt='pt_peoplecode' tabindex='56' onclick='javascript:cancelBubble(event);' href="javascript:submitAction_win0(document.win0,'G_FORM_I9_DRV_G_SSN');" class='PSHYPERLINK' >View</a></span>
</DIV>
<div id="G_FORM_I9_DRV_G_SSN_G_POPUP_SSN" style="visibility:hidden; position:absolute; top:0; left:0;">
<DIV class='ps_pspagecontainer' id='win0divPSPAGECONTAINER_G_POPUP_SSN'>
<table role='presentation' border='0' id='ACE_width' cellpadding='0' cellspacing='0' class='PSPAGECONTAINER' cols='2' width='379'>
<tr>
<td width='16' height='8'></td>
<td width='363'></td>
</tr>
<tr>
<td height='56'></td>
<td valign='top' align='left'>
<DIV id='win0divG_FORM_I9_'>
<table role='presentation' border='0' id='ACE_G_FORM_I9_' cellpadding='0' cellspacing='0' cols='3' width='363' class='PAGROUPBOXLABELINVISIBLE' style='border-style:none'>
<tr>
<td width='36' height='10'></td>
<td width='121'></td>
<td width='206'></td>
</tr>
<tr>
<td height='1'></td>
<td rowspan='2' valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_SSN$9$lbl'><span class='PSEDITBOXLABEL'>Social Security #</span>
</DIV>
</td>
</tr>
<tr>
<td height='27'></td>
<td valign='top' align='left'>
<DIV id='win0divG_FORM_I9_G_SSN$9$'><span class='PSEDITBOX_DISPONLY' id='G_FORM_I9_G_SSN$9$'>888881125</span>
</DIV>
</td>
</tr>
</table>
</DIV>
</td>
</tr>
<tr>
<td height='8' colspan='2'></td>
</tr>
</table>
</DIV>
</DIV>
</td>
</tr>
<!-- OMITTED -->
</table>
Running the Selenium Code
Now, I am trying to enter data into this form, but I keep getting the above exception. When I come to this page, I first am passing through a SSO page to authenticate me. It then redirects me to the form. No problems there. This is my code for doing this (Note that data is a POJO with data in it, and driver is a ChromeWebDriver).
driver.switchTo().frame("TargetContent");
driver.findElement(By.id("G_FORM_I9_G_LAST_NAME")).clear();
driver.findElement(By.id("G_FORM_I9_G_LAST_NAME")).sendKeys(data.lastName, Keys.TAB);
driver.findElement(By.id("G_FORM_I9_G_FIRST_NAME")).clear();
driver.findElement(By.id("G_FORM_I9_G_FIRST_NAME")).sendKeys(data.firstName, Keys.TAB);
driver.findElement(By.id("G_FORM_I9_G_ADDRESS")).clear();
driver.findElement(By.id("G_FORM_I9_G_ADDRESS")).sendKeys(data.address, Keys.TAB);
driver.findElement(By.id("G_FORM_I9_G_CITY")).clear();
driver.findElement(By.id("G_FORM_I9_G_CITY")).sendKeys(data.city, Keys.TAB);
driver.findElement(By.id("G_FORM_I9_G_STATE")).clear();
driver.findElement(By.id("G_FORM_I9_G_STATE")).sendKeys(data.state, Keys.TAB);
driver.findElement(By.id("G_FORM_I9_G_POSTAL")).clear();
driver.findElement(By.id("G_FORM_I9_G_POSTAL")).sendKeys(data.postal, Keys.TAB);
driver.findElement(By.id("G_FORM_I9_G_EMAILID")).clear();
driver.findElement(By.id("G_FORM_I9_G_EMAILID")).sendKeys(data.email, Keys.TAB);
driver.findElement(By.id("G_FORM_I9_G_CITIZEN_CHK")).click();
driver.findElement(By.id("G_FORM_I9_DRV_G_EE_SIGNATURE_PB")).click();
I get the error at various points throughout the process. Sometimes it will fail at the first field it tries to put text into, sometimes the second, and sometimes a later field.
Attempted Solutions
To combat this problem, I have tried calling this method:
private void waitForLoad(WebDriver driver)
{
new WebDriverWait(driver, 30)
.until((ExpectedCondition<Boolean>) wd -> ((JavascriptExecutor) wd)
.executeScript("return document.readyState").equals("complete"));
}
I have also tried this:
new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//*[starts-with(#id, \"G_FORM_I9_\")]")));
What am I missing? What else do I need to check to ensure that the fields are actually accessible? I have tried debugging this in IntelliJ many times, but I suspect the act of stopping at a breakpoint loads the page, so I never see the error, because no elements are stale.
It looks like sometimes calling clear() changes your element reference, and while the page is updating, you are trying to locate this element again and finding the old reference, which causes a StaleElementReferenceException when you sendKeys().
If you already know the fields you're getting the problem with, you can try the following:
WebDriverWait wait = new WebDriverWait (driver, 30);
WebElement element = driver.findElement(By.id("G_FORM_I9_G_LAST_NAME"));
element.clear();
wait.until(ExpectedConditions.stalenessOf(element));
driver.findElement(By.id("G_FORM_I9_G_LAST_NAME")).sendKeys(data.lastName, Keys.TAB);
But if you don't know which fields are causing the problem, and the element doesn't become stale, you will get a TimeoutException.

CSS expression is not working for Select link

table class="s-table table table-bordered table-striped table-hover">
<thead class="p-table-head">
<tbody class="p-table-body">
<tr>
<td>
<td>
<td>
<td>
<td>
<td>
<td>
<div id="div_2_1_2_1_7_r6" class="Action_Group CoachView CoachView_show" data-eventid="" data-viewid="Action_Group5" data-config="config_div_2_1_2_1_7_r6" data-bindingtype="" data-binding="" data-type="com.ibm.bpm.coach.Snapshot_9e739df9_ccc7_4dfa_9b75_8233150ad5bc.Action_Group">
<div id="div_2_1_2_1_7_1_r6" class="ContentBox" data-view-managed="true" style="display: none;"> </div>
<div class="s-action-group clearfix">
<div class="l-nodeId" style=" display: none; "></div>
<div class="p-action-group">
<div id="div_2_1_2_1_7_1_1_r6" class="Action CoachView CoachView_show" data-eventid="boundaryEvent_4" data-viewid="Action3" data-config="config_div_2_1_2_1_7_1_1_r6" data-bindingtype="" data-binding="" data-type="com.ibm.bpm.coach.Snapshot_9e739df9_ccc7_4dfa_9b75_8233150ad5bc.Action">
<button id="div_2_1_2_1_7_1_1_r6-lnk" type="button" style="display: none;">
<a class="p-action-link" href="#action" title="">
<i class="fa fa-user"></i>
<span>Select</span>
</a>
</div>
<div id="div_2_1_2_1_7_1_2_r6" class="Action CoachView CoachView_show" data-eventid="boundaryEvent_8" data-viewid="Action4" data-config="config_div_2_1_2_1_7_1_2_r6" data-bindingtype="" data-binding="" data-type="com.ibm.bpm.coach.Snapshot_9e739df9_ccc7_4dfa_9b75_8233150ad5bc.Action">
</div>
</div>
</div>
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</div>
I have tried x path expression as
//div[#class='row-fluid']/table/tbody/tr[1]/td[7]/div/div[2]/div[2]/div/a/span
//*[#id='div_2_1_2_1_7_1_1_r6']/a/span
Also tried CSS selector as
div[id='div_2_1_2_1_7_1_1_r6'] a[class='p-action-link'] span
any of above identification is not working please let me know if any one has best solutions for the above problem!
Try this XPATH:
//a[span='Select']
If it is not working, please indent the HTML.
Try with below locators.
By.xpath("//div[#id='div_2_1_2_1_7_1_1_r6']//a//span")
or
By.xpath("//div[#id='div_2_1_2_1_7_1_1_r6']//a//span[text()='Select']")
or
By.xpath("//span[text()='Select']")
or
By.cssSelector("div[id='div_2_1_2_1_7_1_1_r6'] a span")
If that div id is not static (I mean dynamically generating unique id everytime) then you should consider some other attribute or some part of it.
By.xpath("//div[contains(#id,'div_2_1')]//a//span")
or
By.xpath("//div[contains(#id,'div_2_1')]//a//span[text()='Select']")
or
By.xpath("//span[text()='Select']")
or
By.cssSelector("div[id*='div_2_1'] a span")

Jump between dynamic textfield

I want to jump between textfields, but these fields are generated dynamically through an iterator from struts-tags:
<s:iterator value="aList">
<td width="50px" align="center">
<s:textfield name="solField" size="2" maxlength="1" style="text-transform: uppercase; text-align:center"/>
</td>
</s:iterator>
I tried jumping with javascript but having the same field name is not working properly.
The code in the browser is (with three items in the list to iterate):
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
Any ideas?
Thanks in advance
How about this? (using jQuery)
$(document).on('keyup', 'input', function(){
if($(this).val().length >= $(this).attr('maxlength'))
{
$(this).nextAll('input:first').focus();
// OR even
// $(this).next('input').focus();
}
});
Is that what you're looking for? http://fiddle.jshell.net/C3jeY/

Connect to a form with changing values with HttpClient in Java

I'm trying to connect to a URL with a form that has this values:
http://aulavirtual.uv.es/
How can I do this if every time I log value changes (time, token_id, hash) ? Please, help me !! I try with HttpUrlConnection and now with HttpClient 4.
<form name="login" method="post" action="/register/">
<input type="hidden" name="form:mode" value="edit">
<input type="hidden" name="form:id" value="login">
<input type="hidden" name="__confirmed_p" value="0">
<input type="hidden" name="__refreshing_p" value="0">
<input type="hidden" name="return_url" value="/dotlrn/index">
<input type="hidden" name="time" value="1352222384">
<input type="hidden" name="token_id" value="423">
<input type="hidden" name="hash" value="3F8865DB5E6603C296428A5A7C0D66C0256D5626">
<tr>
<td class="formulari">Nom d'usuari</td>
<td class="formulari">
<input type="text" id="username" name="username" value="" size="25" alt="Nom d'usuari"></td>
</tr>
<tr>
<TD class="formulari">Contrasenya</TD>
<TD class="formulari">
<input type="password" id="password" name="password" size="25" ALT="Contrasenya d'accés"></TD>
</tr>
<TR>
<TD COLSPAN="2" class="formulari1">
<div align="center">
<input id="login" type="submit" value=" Entreu " alt="Entrar al Aula Virtual">
<IMG BORDER="0" HEIGHT="25" WIDTH="25" SRC="/resources/key.gif" ALT="Entrar en modo seguro" TITLE="Entrar en modo seguro">
</div>
<!--
<Table COLSPAN="2" class="fonsgifs">
<div align="center" class="titol3">
<strong><U>Altres cursos acadèmics</U></SPAN></strong>
</table>
<BR><BR><BR>
<CENTER>
-->
<!--
<img align="center" src="/images/cabeceraOPEN.png" border = 0 align="center" alt="Conferencia OPEN" />
<BR><img align="center" src="/images/ConferenciaSofwareLibre.png" border = 0 align="center" alt="Conferencia Software Libre" />
<BR>7th OpenACS / .LRN Conference
<BR>Conferencia sobre Software Libre en Educación Superior
</CENTER>
-->
</TD>
</TR>
<TR>
<TD class="formulari1" COLSPAN="2" style="text-align:center">
<BR><BR><BR>
</TD>
</TR>
</FORM>
This form uses hidden parameters for security purposes. Every time http://aulavirtual.uv.es/ is displayed these hidden parameters change.
You could try changing your code to do the following:
GET the http://aulavirtual.uv.es/ page.
Parse the resulting HTML to extract the values of the time, token_id, and hash hidden parameters from the form element.
Do the POST as you do now, but pass in these three values instead of the fixed values you are using now.

Categories