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 - selenium

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)

Related

ColdFusion - Using the Query Output to Store Variables For Each Row to Re-Query for Edit

I am definitely a noob at CFML and have been trying to wrap my head around this for some time. I have my query output my data with a Detail button I created that will enter into a new page to edit the information. Each #INV# would have more line items associated to them for review. My goal is to click the button and run a query based off the INV for that given row to return output of all associated line items that need some sort of approval in a new page. Then giving me the ability to edit the data.
I think I need to be able to store the INV column as a variable in my code but am not sure how to accomplish this.
Sorry if it isn't too clear!
<cfquery name="Review" datasource="FINANCE_EQMT_ACCT">
SELECT '1' as ROW, ''ABC CO.' AS OWNER, 'T1234567' AS INV, '50.00' AS TOTAL FROM TBL_TEST
</cfquery>
<div class="container col-xs-12 col-sm-12 col-md-5 col-md-push-1 col-lg-5 col-lg-push-1">
<div class="row">
<table class="table table-striped">
<legend>QUEUE</legend>
<thead>
<tr>
<th class="text-center">#</th>
<th>Owner</th>
<th>Invoice</th>
<th>Amount</th>
<th></th>
</tr>
</thead>
<tbody>
<cfoutput query="Review">
<tr>
<td class="text-center">#ROW#</td>
<td>#OWNER#</td>
<td>#INV#</td>
<td>#TOTAL#</td>
<td class="text-right"><form action="review_action.cfm" method="post"><input class="btn btn-primary" type="submit" value="Detail"></form></td>
</tr>
</cfoutput>
</tbody>
</table>
</div>
</div>
You don't need to save it. You just need to push it over to the next page
...
<td class="text-right">
<form action="review_action.cfm" method="post">
<input type="hidden" name="INV" value="#INV#" />
<input class="btn btn-primary" type="submit" value="Detail">
</form>
</td>
...
review_action.cfm will then process that value as a part of form.inv

Getting elements from a webbrowser

Hoping someone can help me out here.
I'm trying to pull a few bits of info from a web page programatically.
The HTML in question is like this...
<body>
<!-- body content -->
<div id="content">
<!-- Page Header -->
<h1>
PRODUCTNAME™
</h1>
<!-- End Page Header -->
<div id="productImg">
<img id="product.image.large.015" alt="PRODUCTNAME™" src="PRODUCTIMAGEURL" border="0" />
</div>
<div id="productAlt">
<table width="98%" border="0" cellspacing="1" cellpadding="2">
<tr class="altRowLtGray">
<td>
Item #
<span style="text-decoration: inherit;">015</span>
</td>
</tr>
<tr class="altRowLtGray">
<td>
<span style="float: left;">PRODUCTPRICE GBP</span>
<span style="float: right; padding-left: 1em;"></span>
</td>
</tr>
<tr class="altRowLtGray">
<td>
PRODUCTADDITIONALINFO
</td>
</tr>
</table>
</body>
I need to retrieve the 4 items in caps (PRODUCTNAME, PRODUCTIMAGEURL, PRODUCTPRICE and PRODUCTADDITIONALINFO) but am struggling as any examples I find dont seem to be able to be transposed to suit the above HTML... but it could just be me!
I know I need to use either GetElementByID or GetElementByTagName, but i've not used either of these functions before so please forgive my ignorance.
Any help appriciated!!!

Identification of dynamic grid with extjs code in selenium webdriver

I have a dynamic grid populating with Extjs code, for which the element IDs are not visible. Can some one let me know how to find the element i am using selenium webdriver to code. Thanks in advance.
I have added HTML code as i was unable to paste as an image. This HTML is the grid area with which the dynamic grid is displayed.
No Element is available in the HTML except for body elements
<div id="ext-comp-1117" class=" x-panel">
<div id="ext-gen127" class="x-panel-bwrap">
<div id="ext-gen128" class="x-panel-tbar x-panel-tbar-noheader">
<div id="ext-comp-1118" class="x-toolbar x-small-editor x-toolbar-layout-ct">
<table class="x-toolbar-ct" cellspacing="0">
<tbody>
<tr>
<td class="x-toolbar-left" align="left">
<table cellspacing="0">
<tbody>
<tr class="x-toolbar-left-row"></tr>
</tbody>
</table>
</td>
<td class="x-toolbar-right" align="right"></td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="ext-gen129" class="x-panel-body x-panel-body-noheader"></div>
</div>
</div>
</div>
</div>
</div>
I cannot add comments yet, but could you please provide more information:
1. Sample of html?
2. elements not visible but are they present in html?
THanks
Try using Ext.ComponentQuery.query to fetch the id at runtime.

Locate text in a page by using other text in xpath

How can I locate some text in a span in one row using other text that's in other span in other row by xpath in selenium, I don't want to traverse by html tags as html template can be changed dynamically and also I don't have a unique Id.
Below is my code with highlighted text as question and answer text :-
<div id="surveyquescontent">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<span class="mrQuestionText" style="">**Have you chosen your own date for when your electric bill is due?**</span>
</td>
</tr>
<tr>
<td>
<span style="">
<span class="mrQuestionTable" style="display:block;margin-left: 1em;">
<span id="Cell.0.0" style="">
<label for="_Q1_C0">
<span class="mrSingleText" style="">**Yes**</span>
</label>
</span>
</span>
</span>
</td>
</tr>
</tbody>
</table>
</div>
You can try to select the correct <tr> and use following-sibling::tr and continue digging to the desired <span> for example :
//tr[.//span[#class='mrQuestionText']]
/following-sibling::tr[1]
//span[#class='mrSingleText']
In above example I'm using class attribute value to get correct <tr>, you can change it easily to be using text within the <span> if you have to, or using both text and class :
//tr[.//span[
#class='mrQuestionText'
and
.='Have you chosen your own date for when your electric bill is due?'
]]
/following-sibling::tr[1]
//span[#class='mrSingleText']

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

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;
}