What is the exact HTML code to simulate ENTER, ESC, BACKSPACE and DOWN in Selenium IDE 1.3.0?
typeKeys didn't work nor did this:
<tr>
<td>keyDown</td>
<td>id=zc_0_4_3-real</td>
<td>10</td>
</tr>
<tr>
<td>keyUp</td>
<td>id=zc_0_4_3-real</td>
<td>10</td>
</tr>
<tr>
<td>keyPress</td>
<td>id=zc_0_4_3-real</td>
<td>10</td>
</tr>
None of the solutions above helped me, however, the special keys described here this did the trick:
http://blog.reallysimplethoughts.com/2013/09/25/using-special-keys-in-selenium-ide-part-1/
sendKeys | id=search | ${KEY_ENTER}
Special keys - like normal keys, only a bit special. :)
For example to submit a form by pressing enter, the only one I can figure out is:
Command: keyPressAndWait
Target: id=q [depends on your form of course]
Value: \\13 [for enter - any ascii value can go here]
So it looks like this:
<tr>
<td>keyPressAndWait</td>
<td>id=q</td>
<td>\13</td>
</tr>
Hope it helps
Paul
Update:
keyPressAndWait is deprecated
Now you can use:
Command: sendKeys,
Target: id=<your id>,
Value: <your letter in utf8 and not ascii anymore>
For non-printable keys you can have a look at this page:
http://www.testingdiaries.com/selenium-ide-keypress-events/
you can use ${KEY_ENTER} and for other keys as the same as ${KEY_F8},${KEY_ESC}.. etc
Here is a blog post with more details.
For the newer versions of Firefox (22 & 23) the typeKeys command won't work in the Selenium IDE. It's deprecated. You have to use sendKeys.
command = sendKeys
target = css=.someclass
value = ${KEY_ENTER}
If you want to combine text with special keys you can do something like:
command = sendKeys
target = css=.someclass
value = demo${KEY_ENTER}
These methods doesn't work with the TAB key.
To simulate the TAB key pressed we need to use the command fireEvent like this
Clear text field using Ctrl+A and Del (for Selenium IDE):
<tr>
<td>keyDown</td>
<td>id=your text field id</td>
<td>\17</td>
<tr>
<td>keyPress</td>
<td>id=your text field id</td>
<td>\65</td>
<tr>
<td>keyUp</td>
<td>id=your text field id</td>
<td>\17</td>
<tr>
<td>keyPress</td>
<td>id=your text field id</td>
<td>\127</td>
You can use code 13 for enter key, code 9 for tab key, code 40 for down key, 8 for backspace key
The Best Answer to the qs how to Record the Enter Key Through Selenium IDE
<tr>
<td>keyDown</td>
<td>id=txtFilterContentUnit</td>
<td>\13 </td>
</tr>
Its Working i tried that on Selenium IDE here. replace txtFilterContentUnit with your text box name.
hope u can do it -Abhijeet
Related
I have a webpage HTML like this:
<table class="table_type1" id="sailing">
<tbody>
<tr>
<td class="multi_row"></td>
<td class="multi_row"></td>
<td class="multi_row">1</td>
<td class="multi_row"></td>
</tr>
<tr>
<td class="multi_row"></td>
<td class="multi_row"></td>
<td class="multi_row">1</td>
<td class="multi_row"></td>
</tr>
</tbody>
</table>
and tr tags are dynamic so i don't know how many of them exist, i need all td[3] of any tr tags in a list for some slicing stuff.it is much better iterate with built in tools if find_element(s)_by_xpath("") has iterating tools.
Try
cells = driver.find_elements_by_xpath("//table[#id='sailing']//tr/td[3]")
to get third cell of each row
Edit
For iterating just use a for loop:
print ([i.text for i in cells])
Try following code :
tdElements = driver.find_elements_by_xpath("//table[#id="sailing "]/tbody//td")
Edit : for 3rd element
tdElements = driver.find_elements_by_xpath("//table[#id="sailing "]/tbody/tr/td[3]")
To print the text e.g. 1 from each of the third <td> you can either use the get_attribute() method or text property and you can use either of the following solutions:
Using CssSelector and get_attribute():
print(driver.find_elements_by_css_selector("table.table_type1#sailing tr td:nth-child(3)").get_attribute("innerHTML"))
Using CssSelector and text property:
print(driver.find_elements_by_css_selector("table.table_type1#sailing tr td:nth-child(3)").text)
Using XPath and get_attribute():
print(driver.find_elements_by_xpath('//table[#class='table_type1' and #id="sailing"]//tr//following::td[3]').get_attribute("innerHTML"))
Using XPath and text property:
print(driver.find_elements_by_xpath('//table[#class='table_type1' and #id="sailing"]//tr//following::td[3]').text)
To get the 3 rd td of each row, you can try either with xpath
driver.find_elements_by_xpath('//table[#id="sailing"]/tbody//td[3]')
or you can try with css selector like
driver.find_elements_by_css_selector('table#sailing td:nth-child(3)')
As it is returning list you can iterate with for each,
elements=driver.find_elements_by_xpath('//table[#id="sailing"]/tbody//td[3]')
for element in elements:
print(element.text)
I have a webpage that I'm trying to return a value from, however I can't find the right way to grab it with Selenium.
Here's the relevant HTML part:
<table class="table table-striped">
<tbody>
<tr class="hidden-sm hidden-xs">
<th scope="row"><a style="cursor: pointer"
onClick="document.formShip.P_IMO.value='9526942';document.formShip.submit();">
9526942</a>
</th>
I'm trying to get 9526942.
I've tried:
imo = driver.find_element_by_xpath("//*[contains(text(), 'document.formShip.P_IMO.value')]")
and looked around here, but don't know what element this is. I tried looking for the class hidden-sm hidden-xs, to no avail:
imo = driver.find_element_by_class_name('hidden-sm hidden-xs')
if you want to get the text you need to use .text. The .text method can be used with a webelement which some text in that.
in your first example which you tried, you are passing a different parameter with text(). usually when you use text(), you need to pass the value which is there between closing and open tags (the text which you see on the screen)
you simply try this.
imo = driver.find_element_by_xpath(.//tr[#class='hidden-sm hidden-xs']).text
Stuck with watir trying to create a loop to click in all the links included in a table. Currently the table has this format:
<table id="test">
<tbody><tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Link</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>http://facebook.com</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>http://google.com</td>
</tr>
</tbody></table>
And my current attempt looks like:
browser.table(:id => "test").rows do |tr|
tr.each do |td|
td.links.click
end
end
This code above does nothing in the browser & neither returns something in the terminal (no errors, no outputs).
Also tried a different approach using columns:
columns = browser.table(:id => "test").strings.transpose
browser.columns.each do |t|
t.click
browser.back
end
That outputs this error: jsfiddle.rb:24:in <main>': undefined methodcolumns' for # (NoMethodError)
The newer versions of Watir, version 6.0, automatically attempts to relocate stale elements. As a result, as long as the initial page does not change each time you reload it, you no longer need to save some sort of reference data before clicking the links.
It simply becomes:
my_table = browser.table(:id, 'test')
my_table.links.each do |link|
link.click
browser.back
end
This should work to click on each link in the table:
my_table = browser.table(:id, 'test')
table_links = my_table.links.map(&:text)
table_links.each do |link_text|
my_table.link(:text, link_text).click
browser.back
end
Largely based on Justin Ko's answer here.
I want to set my tr class to bg-success when the status is equals 'EXECUTED'. Here is my code:
<th:block th:switch="${order.status}">
<tr th:case="'EXECUTED'" class="bg-success">
<tr th:case="*" class="bg-warning">
<td>...</td>
</tr>
</th:block>
It's obvious that I append two tr rows and don't close the first one, but in reality it's just one appended.
One solution is to rewrite the <td>...</td> in every case but it's a poor one. Is there any better solution without rewriting the <td>..</td> or using javascript?
Hope this helps :
<tr th:class="${order.status.equals('EXECUTED') ? 'bg-success' : 'bg-warning'}">
<td>...</td>
</tr>
I have a tableview and I want to show an image in the first column. My problem is I can't sort the column then. My idea is to set text in the column too and hide the text so it is only for the correct sorting set. Is there a way to do that? Or what other solutions are possible for my problem?
I think this is the perfect example what you wants to do.Still let me know if you have any issue.
Check here
I would have a look at TableColumn.setCellValueFactory() and TableColumn.setCellFactory(). The further is used to provide the actual cell value (used for sorting!), the latter is used to provide the rendering.
In other words: If you need the sort order, you must not change the content, but only the Cell rendering. The methods mentioned above let you do exactly this.
Hope that helps ...
You could do it with just CSS using text-indent. You would also need to set the image as a css background. You did not provide an code of your table, but below is some example:
HTML:
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td class="hidetext image">Text 1</td>
<td>Some text to show</td>
</tr>
<tr>
<td class="hidetext image">Text 2</td>
<td>Some text to show</td>
</tr>
<tr>
<td class="hidetext image">Text 3</td>
<td>Some text to show</td>
</tr>
<tr>
<td class="hidetext image">Text 4</td>
<td>Some text to show</td>
</tr>
</table>
CSS:
.hidetext {text-indent:-9000px}
.image {background:url(http://www.madisoncopy.com/images/jpeg.jpg) no-repeat;}
See how in the left column the text does not show (but it is actually there just indented off the screen).
See this fiddle: http://jsfiddle.net/D297P/