Selenium link for image list based on image name or link name - selenium

I have a menu ribbon that is constructed from tags, Sub lists are hidden until the upper level list is clicked on. How do I identify the target of this image so that I can click on it?
<li class="rbnsel">
<div class="rbl" href="option/index?lfeCyc=Active">
<img src="../icn/op.png">
</img>
Options
</div>
Selenium IDE doesn't identify the image and link (beyond the higher list item), I have tried:
css=rbl:contains('option')
and
xpath=//span[url()='option/index?lfeCyc=Active']
Suggestions of what I should be using to identify the Target would be appreciated.
Edit:
I have added the javascript that triggers the link to be created.. So my Selenium IDE table source is below..
<tr>
<td>selectWindow</td>
<td>null</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>link=Publish</td>
<td></td>
</tr>
<tr>
<td>runScript</td>
<td>var path = $(this).attr('href'); if (e.which == 1 && !e.ctrlKey) {window.location = getCsBaseUrl() + "/" + path;} else {csNewWindow(path);</td>
<td></td>
</tr>
<tr>
<td>MouseOver</td>
<td>//div[contains(#class, 'rbl') and text()='Options']</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[contains(#class, 'rbl') and text()='Options']</td>
<td></td>
</tr>
I guess perhaps my sequence or code is wrong, I have tried all possible combinations but no luck.

WebElement we = driver.findElement(By.cssSelector("div.rbl img"));
Then you could do
string attr = we.getAttribute("src");
Hope that helps

I have fudged a solution - but just using the open command for the links in question. It is not a standard mouseover, mousedown set of actions however it will do for now ;-)
ie command 'open' and Target:
/option/index

Related

How to create a simple table generator for emmet?

I want to create an emmet generator that behaves similar to the loremX but to create a html table.
Right now, what I have is simple table snippet that creates one column:
{
"html": {
"snippets": {
"ftable": "table>(thead>tr>th)+(tbody>tr>td)"
}
}
}
So whenever I type ftable I'll get:
<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
But I want more. I'd like to do something like ftable5:
And get 5 th's/td's instead.
So the emmet code for this case should be:
table>(thead>tr>th*5)+(tbody>tr>td*5)
I don't think I can do that with a simple declaration on the snipper. I suppose I should create a generator for that like the one for loremX, but I have 0 clue on how to even begin, and honestly I couldn't find much information around. It actually surprises me that such a thing doesn't exist yet (or if it does, let me know), as to generate a HTML table you'd still need to type that much code.
I guess your millage may very depending on the tools at hand, but as long as vscode is concerned, it has tabstop options https://code.visualstudio.com/docs/editor/userdefinedsnippets#_snippet-syntax
Let's say your snippet definition looks like the one bellow (notice the $1 placeholder)
"table": {
"scope": "html",
"prefix": "table-n",
"description": "Generates table with n columns",
"body": "table>(thead>tr>th*$1)(tbody>tr>td*$1)"
}
You would typically
type the snippet prefix like table-n
click Enter to select the snippet
the snippet is filled in
cursor for the placeholder blinks
type the number of expected columns
click Tab to trigger the emmet generation
the end result should look like this when $1 is say 3
<table>
<thead>
<tr>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

How to extract the text 8 from the 2nd row and 2nd column as per the html through Selenium and VBA

Using selenium vba i want 2nd row and 2nd column value from webpage table below is the code which i have try but it capture all table.
The output which i want is 8.
driver.FindElementByXPath("//table[contains(#class,'zedoLocTable')]").text
Please find the below html code.
<tr>
<td colspan="4">
<div id="localityTiers">
<br><br>
<table class="zedoLocTable" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<th>TYPE</th>
<th>TIER</th></tr>
<tr>
<td><b>Resedential Sale</b>
</td><td>8</td>
</tr>
<tr><td><b>Resedential Rent</b>
</td><td>5</td>
</tr><tr>
<td><b>Commercial Sale</b>
</td><td>1</td>
</tr><tr>
<td><b>Commercial Lease</b>
</td><td>1</td>
</tr></tbody></table><table></table></div>
</td>
</tr>
Below is the table pic
As per the HTML you have shared to extract the text 8 you can use the following solution:
driver.FindElementByXPath("//table[#class='zedoLocTable']//tr/td/b[contains(.,'Resedential Sale')]//following::td[1]").text
You can use a faster CSS selector, than using xPath, if you are working with later IE or other browers apart from IE
Debug.Print driver.FindElementByCSS(".zedoLocTable td + td").innerText

Copy text from website using Selenium for python

I'm trying to copy text from a website with the following code and I want it to automatically click the "NEXT" button at the end of the table, without clicking it the code works just fine but when I add the last line to click it gives the error:
"Message: Element is no longer attached to the DOM Stacktrace: at
fxdriver.cache.getElementAt
(resource://fxdriver/modules/web-element-cache.js:9354)
at Utils.getElementAt (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:8978)
at WebElement.getElementText (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:11965)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:12534)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:12539)
at DelayedCommand.prototype.execute/< (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:12481)"
The code I'm using is:
driver = webdriver.Firefox()
driver.get("https://it.website.com/Statistics")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
Next_first = 0
Next_first = driver.find_elements_by_id("next")[0]
data_vector [i]=driver.find_elements_by_class_name("tn")[i].text
Next_first.click()
While the website code is:
<tr>
<td class="tn"> text
</td>
<table class="table class" id="table id">
<thead>...code for table title...
</thead>
<tbody>
<tr>
<td class="tn">data
</td>
</tr>
</tbody>
<dd>
<a class="option clickable" id="next" data-page="1">NEXT</a>
</dd>
</tr>
Is there more than the html-source, like javascript?
Because the input could be detached by javascript, which means you have to wait for it to load properly ( driver.implicitly_wait(#seconds) )
here the link to the discription of "implicit-waits"
The second solution could be that you have to clear the cache/cookies of the webdriver before testing, which is described here

how to get Table element from a Div that has a Heading tag with a known text - using selenium and java

<h3>Movers and Shakers</h3>
<p>
<strong>Strategy Hint 1:</strong><br>
<strong>Strategy Hint 2:</strong><br>
</p>
<table cellspacing="0" cellpadding="0" border="1">
<tbody>
<tr>
<td> </td>
<td>ExternalId</td>
<td>Name</td>
<td>Price cents</td>
<td>Brand</td>
<tr>
<tr>
<td>1</td>
<td>123</td>
<td>Draw</td>
<td>2</td>
<td>Ciko</td>
<tr>
Now, the know text in the h3 tag is 'Movers and Shakers'. The table and h3 are in a Div tag. Now, how do I get the table for this specific div that has that specific known text('Movers and Shakers').
With the help of xpath, use following code to return the DIV element that contains a heading H3 with the text Movers and Shakers:
WebElement div = driver.findElement(By.xpath("//div[h3[text()='Movers and Shakers']]"));
Ant then, find the table inside this div web-element:
WebElement table = div.findElement(By.xpath(".//table"));
This will return the table element you want:
WebElement table = driver.findElement(By.xpath("//div[h3[contains(.,'Movers and Shakers')]]")).findElement(By.tagName("table"));
this short line worked
WebElement table = driver.findElement(By.xpath("//h3[contains(text(),'Movers and Shakers')]/following-sibling::table"));

How to use loops in Selenium IDE

Is for loop present in Selenium IDE? if yes, How can I use it in Selenium IDE?
Thanks,
Nit
We can use while loop and goto function in Selenium IDE.
For that we must install the addon flow control. Add from the following link:
Selenium IDE: Flow Control
After installing you will get the commands while and gotoif in Selenium IDE
1) Example for while loop
<tr>
<td>getEval</td>
<td>index = 0;</td>
<td></td>
</tr>
<tr>
<td>while</td>
<td>index < 10;</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>index</td>
<td>value</td>
</tr>
<tr>
<td>echo</td>
<td>${value}</td>
<td></td>
</tr>
<tr>
<td>getEval</td>
<td>index++;</td>
<td></td>
</tr>
<tr>
<td>endWhile</td>
<td></td>
<td></td>
</tr>
2) Example for gotoif
store | 10 | x
gotoIf | storedVars['x'] > -2 && storedVars['x'] <50 | true
getEval| alert("Condition Fails")
gotolabel | finish
label | true
getEval | alert("Condition Pass")
label | finish
try this Thank you..
Yes, we can have looping in IDE
You can refer below URL for looping in IDE
Selenium IDE: How to Pass Variables
How to write gotoif (i > -2 && i < 100) in Selenium IDE?
http://radical-qa.blogspot.in/2012/02/selenium-ide_09.html