Identification of dynamic grid with extjs code in selenium webdriver - selenium

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.

Related

Unable to locate element using xpath

Am very new to Selenium just learnt few things and trying to automate.Unable to locate an element in Selenium webdriver for the below one:
<div class="navBg withSubMenu">
<table id="topnav" class="navTable" cellspacing="0" cellpadding="0" style="-moz-user-select: none; cursor: default;">
<tbody>
<tr>
<td class="logoCell navCell" valign="top">
<td class="navItem navCell relative selected">
<td class="navItem navCell relative notSelected">
<a class="content tasks" href="/tasks/otasklist.do">
<div class="label" style="z-index:155; ">TASKS</div>
<div class="img"> </div>
</a>
</td>
<td class="navItem navCell relative notSelected">
<a class="content reports" href="/reports/reports.do">
</td>
<td class="navItem navCell relative notSelected">
<td class="menuCell navCell" valign="top">
</tr>
<tr class="secondLevelRow">
</tbody>
</table>
I have written code like
driver1.findElement(By.xpath("//*[Contains(#class,'content tasks')]")).click();
Anyone please help me.
And also please suggest some sites or links to learn more about locators especially xpath. I tried few but not getting it in depth.
Thanks in advance.
Start contains with a lower case c:
driver1.findElement(By.xpath("//*[contains(#class, 'content tasks')]")).click();
<a class="content tasks" href="/tasks/otasklist.do">
driver1.findElement(By.xpath("//a[#class='content tasks']")).click();

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)

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

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']

Element is not visible

I'm trying to parse and manipulate some data via Selenium and java (using Firefox as a browser and Ubuntu as an os).
The HTML code:
...
<div id="someName1">
<div id="someName2">
<div id="someName3">
<a class="sendMessegeLink" onclick="open_win(...)" title="someText1">
<img style="padding-left:5px; vertical-align:middle" src="..."/>
someText1
</a>
</div>
<table class="areaTable">
<tbody>
<tr>
<tr>
<tr class="someName4">
<td colspan="4">
<div id="SomeUniqueId" class="someName5" style="display: block;">
<table class="someName6">
<tbody>
<tr>
<tr>
<td colspan="2">
<a class="sendMessegeLink" onclick="open_iframe('...)" title="someText2">
<img style="padding-left:5px; vertical-align:middle" src="..."/>
<!-- WANTED ("not currently visible") ELEMENT -->someText2
</a>
<span class="remark"> someText3</span>
</td>
</tr>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tr>
</tr>
</tbody>
</table>
</div>
</div>
...
I've been trying to click the element "someText2" of class "sendMessegeLink" with :
WebElement inputElement = driver.findElement(By.xpath(".//*[#id='SomeUniqueId']/table/tbody/tr[2]/td/a"));
than :
WebElement inputElement = driver.findElement(By.cssSelector(".personalDetailsTable .sendMessegeLink"));
and than by manipulating the DOM display attribute (after reading this ) :
javascriptExecutor js = (JavascriptExecutor) driver;
WebElement w = (WebElement) js.executeScript("return document.getElementByClassName('sendMessegeLink').removeAttribute('display');");
and lastly just by Thread.sleep(5000) before accessing element in case everything isn't loaded at the DOM (in addition to driver.manage().timeouts().implicitlyWait(sec, TimeUnit.SECONDS) that I use.
I get Element is not currently visible and so may not be interacted with
Try this
WebElement tmpElement= driver.findElement(elementLocator); // Try all your combination here
JavascriptExecutor executor = JavascriptExecutor)driver;
executor.executeScript(“arguments[0].click();”, tmpElement);