Row text from a dynamic table - extjs

I am pretty new to Selenium Webdriver, so pardon me for all d 'noob' terminology used.
I have a dynamic table on the page, with 4 columns in the table. Out of this, only the first column name can be edited. The table looks like this :
Now using Webdriver, I need to locate 'group102' and verify the Level and the number of Cards (basically the text of the rest of the two columns) corresponding to 'group102'. The key point to note here is that this group is dynamic in nature. Right now, its sitting in row 3 but tomorrow, it may be on row 1 or row 10.
I am using Visual Studio (C#) and Selenium webdriver.
Please let me know how can I progress
EDIT :
HTML CODE:
<div id="formbland-1013" class="x-panel x-panel-default x-form-bland x-form-base" style="height: 9588px;">
<div id="formbland-1013-body" class="x-panel-body x-panel-body-default x-panel-body-default" style="left: 0px; top: 0px; width: 680px; height: 9588px;">
<span id="formbland-1013-outerCt" style="display: table; width: 100%; table-layout: fixed;">
<div id="formbland-1013-innerCt" style="display:table-cell;height:100%;vertical-align:top;">
<div id="ext-comp-1026" class="x-panel x-panel-default x-form-bland x-form-base" style="width: 680px; height: 47px;">
<div id="ext-comp-1036" class="x-panel x-panel-default x-form-bland x-form-base" style="width: 680px; height: 9541px;">
<div id="ext-comp-1036-body" class="x-panel-body x-panel-body-default x-panel-body-default" style="left: 0px; top: 0px; width: 680px; height: 9541px;">
<span id="ext-comp-1036-outerCt" style="display: table; width: 100%; table-layout: fixed;">
<div id="ext-comp-1036-innerCt" style="display:table-cell;height:100%;vertical-align:top;">
CODE WHICH I AM TRYING :
ReadOnlyCollection<IWebElement> select = WebDriver.FindElements(By.XPath("//td[contains(text(),'group102')]"));
if ("group102e".Equals(select.ToString()))
{
throw new SystemException("Group matches according to the Access");
}
else
{
throw new SystemException("Group does not matches according to the Access");
}

I can't provide exact code as I don't know the HTML for the table. But here are the code in theory.
You get the IWebElement input first by text first, then go to ancestor td's siblings (i.e. the next two column cells in this row), then get the element's text.
IWebElement inputGroup = WebDriver.FindElement(By.CssSelector("tbody input[value='group101']"));
IWebElement level = inputGroup.FindElement(By.XPath("(.//ancestor::td/following-sibling::td)[1]"));
string levelA = level.Text;
My questions about your code:
"group102e".Equals(select.ToString()) doesn't make sense, since your select is ReadOnlyCollection<IWebElement>, which is a list of IWebElements, ToString won't get you anything useful?
var location = WebDriver.FindElement(By.CssSelector("tbody input[value='Practice Wide Group 2']")).Location.ToString();, what do you want here? The location of the element (which is in the type of System.Drawing.Point)?

Related

Display several sequences of events with possible line break in middle [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am a HTML / CSS newbie.
I need to do something like this:
My web page is receiving sequences of events dynamically and I would like to visualize them on in the page.
I would like one sequence of events to be in a box, with lots of slots, and each slot has the event id.
So if I have several sequences, then I will have several such boxes.
However, the length of a sequence is dynamic. And the web page's window might be adjusted by the users, so even for a sequence, if it is too long or the window is too narrow, I have to break the box into several lines.
the above is my drawing of the design.
The A, B, etc, are the sequence title, then the numbers are the ids.
ideally, the space of all events / sequences should be as compact as possible.
And if a box has to change line, then it should be half-borded to indicate the continuous.
How can I do that? using CSS 3?
And also the framework I am using is AngularJS to control the data / UI binding, even if I manage to handle this case, how to dynamically bind the data to adjust this requirement?
Thanks
Doing this in CSS is tricky, because you want a border between elements only if those elements are on the same line. CSS doesn't know anything about wrapping.
I've solved the problem by:
Adding a left border on all boxes
Adding a right border on the last box only.
Adding a -1px left margin on all boxes except the first.
Placing the boxes in a container with overflow: hidden.
Having the right border on the last box only solves the right-hand issue.
The -1px left margin solves the left-hand issue.
Snippet:
.sequences {
overflow: hidden;
}
.sequence > div {
border: 1px solid black;
border-right: none;
height: 50px;
float: left;
margin-bottom: 10px;
}
.sequence > div:last-of-type {
border-right: 1px solid black;
margin-right: 20px;
}
.sequence > div:not(:first-of-type) {
margin-left: -1px;
}
.yellow div {background: yellow; width: 100px;}
.green div {background: lightgreen; width: 80px;}
.blue div {background: lightblue; width: 120px;}
<div class="sequences">
<div class="sequence yellow">
<div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div>
</div>
<div class="sequence green">
<div></div><div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div><div></div>
</div>
<div class="sequence blue">
<div></div><div></div><div></div>
<div></div><div></div><div></div>
</div>
</div>
You can solve this using CSS by doing something like this.
I've given each sequence element a top, left and bottom border. T
This will give the illusion of a right border when the elements are floated next to eachother but when they're the last on that line it will brake of as per your request.
I also added a right border to the last div element and the last div in each section.
Fiddle
div{
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
float:left;
background: #eee;
border: 1px solid #000;
border-width: 1px 0 1px 1px;
margin-bottom: 10px;
}
div.last{margin-right: 5px;}
div.last,
div:last-child{border-right-width: 1px;}
<div class="seq-1">1</div>
<div class="seq-1">2</div>
<div class="seq-1">3</div>
<div class="seq-1">4</div>
<div class="seq-1 last">5</div>
<div class="seq-2">1</div>
<div class="seq-2">2</div>
<div class="seq-2 last">3</div>
Edit:
I just noticed you wan't the border to be 0px/blank on the last element and the first element each row. Now that is a bit trickier.
I'm not positive there's a good solution to solving that using css since your sequences seem to be dynamic.
Please correct me if I'm wrong, but I think you need to use javascript to manage this.
Edit 2: CSS and JQuery solution
I made a quick jquery solution that utilies my previously provided CSS code.
The jQuery script removes the left border if the elements left offset(within it's parent) is 0 and if the element is not the first element in each sequenc(first class added).
Fiddle
var containerOffset = $('.container').offset().left;
setBorderWidth();
$(window).resize(function(){
setBorderWidth();
});
function setBorderWidth(){
$('.block').each(function() {
var childOffset = $(this).offset().left;
if(childOffset - containerOffset == 0 && !$(this).hasClass('first'))
$(this).css("border-left-width", "0px");
else
$(this).css("border-left-width", "1px");
});
}
.container{width: 100%;}
.block{
width: 100px;
height: 50px;
line-height: 50px;
text-align: center;
float:left;
background: #eee;
border: 1px solid #000;
border-width: 1px 0 1px 1px;
margin-bottom: 10px;
}
.block.last{margin-right: 5px;}
.block.last,
.block:last-child{border-right-width: 1px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<div class="container">
<div class="seq-1 block first">1</div>
<div class="seq-1 block">2</div>
<div class="seq-1 block">3</div>
<div class="seq-1 block">4</div>
<div class="seq-1 block last">5</div>
<div class="seq-2 block first">1</div>
<div class="seq-2 block">2</div>
<div class="seq-2 block last">3</div>
</div>
What I would recommend is to have 3 CSS classes
1) beginning of sequence
2) middle of sequence
3) end of sequence
then display different borders using:
.beginning-of-seq {
border-top-style: solid;
border-right-style: none;
border-bottom-style: solid;
border-left-style: solid;
}
for instance.
about the angular part just use ng-repeat="seq in sequences" for instance and then render the sequence with the classes you created so it will look good (of course you need the scope to have the sequences)
<span ng-repeat="seq in sequences">
<span class="beginning-of-seq"> {{seq.title}} </span>
<span class="middle-of-seq ng-repeat="elem in seq.otherElements">{{elem}}</span>
<span class="end-of-seq"> {{seq.lastElem}} </span>
</span>
</span>
this is a bit crude and i don't know how you implemented it but it should give you an idea where to start
This HTML/CSS should do the trick. As you mentioned about the user having different resolutions, I've used percentages for the widths (depending on your scenario, media queries may be needed).
.container {
width: 30%; /*Change this to fit your design*/
}
.seq {
display: inline;
border: 0.1em solid #000;
margin-right: 1em;
}
.seq .item {
display: inline-block;
width: 5%; /*Change this to fit your design*/
margin-bottom: 1em;
}
.seq .item:not(:last-child) {
border-right: 0.1em solid #000;
}
<div class="container">
<div class="seq">
<div class="item item-title">A</div>
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
<div class="seq">
<div class="item item-title">B</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
<div class="seq">
<div class="item item-title">C</div>
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
</div>
<div class="seq">
<div class="item item-title">D</div>
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
</div>
</div>
About the AngularJS binding:
In your controller define your array of sequences and some functions to manipulate the sequences:
$scope.sequences = [];
$scope.addSequence = function(sequenceName){
var newSequence = { name : sequenceName, events: [] };
$scope.sequences.push(newSequence);
};
$scope.addEventToSequence = function(sequenceName, event){
var sequence = getSequence(sequenceName); // write this function to get the right sequence from the array
sequence.events.push(event);
}
Now in your html loop over the sequences and events using ng-repeat
<ul>
<li ng-repeat="sequence in sequences">
<ul>
<li>{{sequence.name}}</li>
<li ng-repeat="event in sequence.event">{{event.name}}</li>
</ul>
</li>
</ul>

Adding border-radius to a map

I have a website running on a mapping platform called Ushahidi. The default template is quite boxy so I was fiddling with the CSS and rounding everything off using border-radius.
It has helped with other elements but the map is such a square it won't ease up!
It might be that it's not possible, wondered if anyone here had any experience of this. The html using inspect element and view source are different. Not sure what this means exactly but guessing that the html is pulled in by the map provider?
Here is the html on view source:
<div class="map " id="map"></div>
<div style="clear:both;"></div>
<div id="mapStatus">
<div id="mapScale"></div>
<div id="mapMousePosition"></div>
<div id="mapProjection"></div>
<div id="mapOutput"></div>
</div>
I've added a screen of inspect element HTML too. Looks like it's using "Open Layers". I've heard of that but don't fully understand whats going on.
Is it possible to round the edges of my map? Here is the site if that helps: http://tinyurl.com/c8djrvr
Apply the border-radius to two layers.
CSS
div.map {
border: #999 1px solid;
width: 800px;
height: 366px;
position: relative;
height: 650px;
border-radius: 25px; /* ADD THIS */
}
#OpenLayers_Map_11_OpenLayers_ViewPort {
border-radius: 25px; /* ADD THIS */
}
It works. Use however many pixels you want. I used 25px.
I would suggest more general and safer CSS selectors (since ID #OpenLayers_Map_11_OpenLayers_ViewPort is generated by OpenLayers and it's value is unpredictable; and OL 2.12 and older produce ID's, that contain dot and are therefore unsuitable for CSS selectors):
.olMap, .olMapViewport {
border-radius: 25px;
}

how to select all the extjs dropdown values in selenium webdriver

I am trying to a select option from extjs combo box.
Here in the below code listElements is giving only the visible options(which are shown in the screen) and not all the options.
Here am restricted to select one of the options which are available in the screen.
I want to select the value which are in the bottom of the list.
I don't find any option to drag down the list to select the desired option.
List<WebElement> listElements = TestUtil.getWebDriver().findElements((By.className("x-boundlist-item")));
for(WebElement ele : listElements){
if(ele.getText().equals(TestUtil.getValue(DateTimeConstants.TIMEZONE_INPUT_VALUE))){
ele.click();
break;
}
}
Please find the html :
This is the combo box html:
<input id="currentTimezone-inputEl" class="x-form-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" type="text" style="width: 100%; -moz-user-select: text;" name="dateTimeData.selectedTimezone" value="-- Please Select --" autocomplete="off" aria-invalid="false" data-errorqtip="">
Options are available below like this:
<div id="ext-gen1024" class="x-reset">
<div id="ext-gen1074" class="x-reset">
<div id="ext-gen1076" class="x-css-shadow" role="presentation" style="z-index: 19000; left: -9999px; top: -9995px; width: 355px; height: 296px; box-shadow: 0px 0px 4px rgb(136, 136, 136); display: none;"></div>
<div id="ext-gen1079" class="x-css-shadow" role="presentation" style="z-index: 19000; left: 20px; top: 321px; width: 355px; height: 296px; box-shadow: 0px 0px 4px rgb(136, 136, 136); display: none;"></div>
<div id="boundlist-1022" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default" tabindex="-1" style="left: 20px; top: 317px; width: 355px; z-index: 19001; height: 300px; display: none;">
<div id="boundlist-1022-listEl" class="x-boundlist-list-ct" style="overflow: auto; height: 299px;">
<ul>
<li class="x-boundlist-item" role="option">Africa/Abidjan</li>
<li class="x-boundlist-item" role="option">Africa/Accra</li>
<li class="x-boundlist-item" role="option">Africa/Addis_Ababa</li>
<li class="x-boundlist-item" role="option">Africa/Algiers</li>
<li class="x-boundlist-item" role="option">Africa/Asmara</li>
<li class="x-boundlist-item x-boundlist-selected" role="option">America/St_Lucia</li>
</div>
</div>
</div>
Yes, I can reproduce this issue. The reason is that Selenium won't click on invisible elements, each of the invisible element's text will also be empty.
Here most of the combo list elements are invisible, so ele.getText() won't get you anything for them. As a result, you won't be able to compare the text with the one you want.
However, the workaround is, without using ele.getText() to get the text, you can try use textContent attribute of an element to get the text. Also, Selenium won't click on invisible element, so you need to use Actions click() rather than normal click(). Below is how you can do it.
List<WebElement> listElements = TestUtil.getWebDriver().findElements((By.cssSelector(".x-boundlist:not([style*='display: none'])")));
for(WebElement ele : listElements){
if(ele.getAttribute("textContent").equals(TestUtil.getValue(DateTimeConstants.TIMEZONE_INPUT_VALUE))) {
// print out ele.getAttribute("textContent") if you want
// ele.click(); ElementNotVisible exception may be thrown
new Actions(TestUtil.getWebDriver()).click(ele).perform();
break;
}
}
}
To solve this we can use xpath in the following manner. The reason why a country is not selected is it is not visible and for invisible elements selenium cannot perform the action.
We have to first make the countries list visible by clicking on the input box. Once the list is visible we can select any of the country in the list.
// Code to make the country list visible
WebElement element = driver.findElement(By.xpath("//div[contains(#id, 'boundlist')]"));
element.click();
//To click on some country in the drop down
driver.findElement(By.xpath("//div[contains(#id, 'boundlist')]//ul//li[text() = 'Africa/Abidjan']")).click();
//To make a reusable method
public void selectCountry(String countryName)
{
driver.findElement(By.xpath("//div[contains(#id, 'boundlist')]//ul//li[text() = '" +countryName +"']"));
}

Selenium WebDriver ExtJS drop-down

I'm trying to find list of element in ExtJS drop-down. I found a good solution on stackoverflow, though it doesn't work for me.
Solution in C#:
public void ClickComboItem(IWebElement input, string target)
{
input.Click();
IList<IWebElement> comboItems = _driver.FindElements(By.XPath("//*[contains(#class, 'x-combo-list') and contains(#style, 'visibility: hidden;')]//*[contains(#class, 'x-combo-list-item')]"));
comboItems.First(item => item.Text.Trim() == target).Click();
}
From here.
Part which I need to automate look like this:
<div class="x-ie-shadow" id="ext-gen546" style="z-index: 12004; filter: progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=4); WIDTH: 351px; display: none; height: 301px; top: 186px; left: 1187px;"/>
<div class="x-layer x-combo-list " id="ext-gen544" style="z-index: 12005; position: absolute; width: 350px; height: 302px; visibility: hidden; font-size: 12px; top: -10000px; left: 0px;">
<div class="x-combo-list-inner" id="ext-gen545" style="width: 348px; height: 300px; overflow: auto;">
<div class="x-combo-list-item" _nodup="30813" viewIndex="0">
<div class="x-combo-list-item" _nodup="30813" viewIndex="1">
Actual click on the pointer is executed and I can see see drop-down list on the page, though comboItem returns '0' results. I assume I should adjust xPath correctly for my case, though it seems for me that it should work, as soon as structure is very similar with an example from the post I mentioned above.
It seems that the xPath is not correct.
You gave "visibility: hidden;"
Try with ""visibility: visible;"
public void ClickComboItem(IWebElement input, string target)
{
input.Click();
IList<IWebElement> comboItems = _driver.FindElements(By.XPath("//*[contains(#class, 'x-combo-list') and contains(#style, 'visibility: visible;')]//*[contains(#class, 'x-combo-list-item')]"));
comboItems.First(item => item.Text.Trim() == target).Click();
}
You can take a different way without using Xpath
IWebElement dvInner = driver.FindElement(By.Id("ext-gen545"));
IList<IWebElement> comboItems = dvInner.FindElements(By.ClassName("x-combo-list-item"));
Try to implement using stable id of any of the parent nodes.Basically using the xpath-axis concept.

Update method bug in extjs

In my extjs project, I have some panel's to which I am showing toolbar on mouseEnter event. This is working fine. But when I just update the panel with new html then the mouseenter event is not working on it.
panel.update('hello');
Then I realised through Chrome developer tool that the update method is erasing the last nested div inside panel before writing the new text to it (ie 'hello').
Each panel has 3/4 nested div's but when we use update(), the panel has only 2 nested div's?
This was the main reason which was not invoking the mouseenter event on the panel because I think the Ext is unable to identify the panel as a valid panel after update() method.
Anyway, later I solved this issue by checking the panel variable in chrome console like below.
panel.body.dom.childNodes[0].children[0].childNodes[0].data = 'hello';
The above implementation looks disgusting but it worked for me. Any other nice way to do this?
Edit :
//In controller
this.control({
'#monthCalendar>panel>panel': {
render: function(container){
container.on('mouseenter',function(){
//do something here
},container,{element: 'el'});
}
}
})
Before Update:
<div class="x-panel x-box-item x-panel-default" id="panel-1078" style="left: 870px; top: 0px; margin: 0px; width: 174px; height: 52px;">
<div id="panel-1078-body" class="x-panel-body x-panel-body-default x-panel-body-default x-box-layout-ct" style="width: 174px; height: 52px; left: 0px; top: 0px;">
<div id="panel-1078-innerCt" class="x-box-inner " role="presentation" style="height: 50px; width: 172px;">
<div id="panel-1078-targetEl" style="position: absolute; width: 172px; left: 0px; top: 0px; height: 1px;">
March 01
</div>
</div>
</div>
</div>
After update:
<div class="x-panel x-box-item x-panel-default" id="panel-1078" style="left: 870px; top: 0px; margin: 0px; width: 174px; height: 52px;">
<div id="panel-1078-body" class="x-panel-body x-panel-body-default x-panel-body-default x-box-layout-ct" style="width: 174px; height: 52px; left: 0px; top: 0px;">
February 01
</div>
</div>
I am available on Sencha chat room.
Your event handler stops working because your update() erases the inner elements added by the panel's layout.
You are using either HBox or VBox layout on your panel, which adds additional HTML elements inside the main one, as you noticed. If you call update() on the main component's element, you erase the inner elements added by the layout, including that on which your event handler was listening.
The solution is to either:
use a simpler layout on your panel, such as Auto;
or
update the inner element added by the layout:
panel.getLayout().targetEl.update('Updated');
If you want to update the content of a panel, you should call
panel.body.update('hello');
This will update content area element only and will not ruin the panel integrity. As far as I know, calling update directly on panel is wrong, because call to function inherited from AbstractComponent will not take into account internal panel's structure and will overwrite essential panel's markup.

Resources