tbody . each( ) ; method missing watir - watir

Hi there I am not sure if i am using the wrong watir syntax or if there is something wrong with my watir. Below if the code that I am writing to go through each row of a table body. Be
e.frame(:name => "content").frame(:name => "main").tbody(:class => "blacklabel").each(){|i|.....}
when i run this code i get a missing error code. Also when i try
e.frame(:name => "content").frame(:name => "main").tbody(:class => "blacklabel").length()
I get a missing method error. Below is the website that i am using.

You want to iterate over the rows collection rather than the table body - ie you need to call rows() before the each(). So you want to do:
my_table = e.frame(:name => "content").frame(:name => "main").tbody(:class => "blacklabel")
my_table.rows.each{|i|.....}
The tbody element uses the TableSection class. The TableSection API can be seen here - http://rdoc.info/gems/watir-classic/Watir/TableSection.

Related

Elasticsearch.NET search records starts with a value in a string field (NEST)

I have an issue for searching on elastic. I use NEST library for search and I try to get records that is customername field start with 'GÖKDEMİR' (for example)
var response = await _elasticClient.SearchAsync<AccountAddressInfo>(p => p
.Query(q => q
.MatchPhrasePrefix(m => m
.Field(f => f.CustomerName)
.Query(filter.CustomerName)
)
)
.Size(101));
With this search, I get the record on response that contains 'GÖKDEMİR' in customername field but I want to get fields starts with 'GÖKDEMİR'.
How can I do this.
In case your customername field is a term type, then you can try to use just Prefix where you are using MatchPhrasePrefix like so :
.Query(q => q
.Prefix(m => m
.Field(f => f.CustomerName)
.Query(filter.CustomerName)
)
)
.Size(101));

Get cells of rows

I'm successfully getting the rows of a table as so:
var rows = await page.evaluate(() => Array.from(document.querySelectorAll('.summary > tbody > tr'), element => $(element)))
How do I get the children of each row as an array?
Do I do ... Array.from(rows[i].querySelectorAll(...?
I've tried a few different methods but I can't figure it out.
I understand your question so that you want to get only the values of cells grouped as an array for each of the rows present in a table. If that's correct, then you could do it in this way:
const rows = await page.evaluate(
() => Array.from( document.querySelectorAll('table > tbody > tr') ) // Get the rows as an array
.map(row => Array.from( row.querySelectorAll("td") ) // For each row get its cells as an array
.map(td => td.textContent)) // Replace each cell in the latter array with its text
)
Short answer:
Use the following code, which queries the direct child elements of the tr elements:
const rowChildren = await page.$$('.summary > tbody > tr > *');
Long Answer
Your code is not doing what you think it is doing. I go over your code, to show you the problem.
Problem
Here is your code again:
var rows = await page.evaluate(
() => Array.from(
document.querySelectorAll('.summary > tbody > tr'),
element => $(element),
)
)
What this code does is:
Run document.querySelectorAll in the browser
Map each element in the NodeList to a jQuery object (I'm assuming $ is jQuery here)
Call JSON.stringify on the array of jQuery objects (to serialize them)
puppeteer transfers your serialized data from the browser environment to the Node.js environment
rows now contains an array of "jQuery objects", without reference to their actual DOM node
So, this code does not give you the handle to the jQuery elements in the Node.js environment as the function page.evaluate can only return serializable objects (which DOM nodes are not). Although it looks like you successfully queried the DOM nodes, these objects are just the "jQuery wrappers" around the DOM nodes without the actual DOM nodes as these were not serialized.
Solution
To query DOM nodes from the browser environment, you have to use a function like page.$$, which can return ElementHandles. Therefore, using the following code, will return the actual tr rows:
const rows = await page.$$('.summary > tbody > tr');
To then further query their child elements, you can simply add a > * selector to the end, which will query all direct child nodes of the tr rows:
const rowChildren = await page.$$('.summary > tbody > tr > *');
i think you might be looking to do something along these lines
const rows = await page.evaluate(
() => Array.from(
document.querySelectorAll('.summary > tbody > tr'),
element => $(element)
)
)
let children = []
for (const row of rows)
children = [...children, ...row.children]

Cheerio scraping: Not able to find elements in HTML response

I have a HTML response as:
<table id="\"tableone\"" class="\"sortable">
Now ,when I tries to find element with the ID #tableone ,it returns nothing but if I try to find using 'table' it works.
var $ = cheerio.load(html)
console.log('tableone:'+ $('#tableone').length) => 0
Try with jQuery's wild card selector. In your case you can use the * selector which will fetch all matching entries which matches the term tableone
You can try like this,
console.log('tableone:'+ $('[id*=tableone]').length);
Hope this helps!

Java script drop down menu access Watir-web driver

I am having problems trying to access some a link in a drop down menu In a web site. When you put your cursor over the button, as shown in the first picture, the menu drops down. Below that is a picture of the webpage script. What i want to do is click the search specifications button inn the drop down menu.
the like of code would go something like this :
e.frame(:name => "content").frame(:name => "main").a(:index => 0).click.a(:index => 10).click
However, that is not a valid peace of code, i just don't know the right way of doing it.
< e.frame(:name => "content").frame(:name => "main")
=> #<Watir::Frame:0x7f74b4d4 located=false selector={:name=>"main"}>
irb(main):064:0> my_frame.a(:text => 'Operations').click
Watir::Exception::UnknownObjectException: unable to locate element, using {:text
=>"Operations", :tag_name=>"a"}
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.1/lib/watir
-webdriver/elements/element.rb:365:in `assert_exists'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.6.1/lib/watir
-webdriver/elements/element.rb:95:in `click'
from (irb):64
from C:/Ruby193/bin/irb:12:in `<main>'
irb(main):065:0>
The dropdown menu does not appear to be in the HTML part that you posted. It is likely further down in the HTML.
Instead of trying to locate by index, which can easily change, you could locate by text. Try:
my_frame = e.frame(:name => "content").frame(:name => "main")
my_frame.a(:text => 'Operations').click
my_frame.a(:text => 'Search Specifications').click
This assumes that the 'Search Specifications' link is also in the same frame as the 'Operations' link.
Try this:
myframe.a(:text, 'Operations').fire_event 'mouseover'
myframe.a(:text, 'Search Specifications').click
Not sure if this is perfect, but the idea is that you make the link in the drop down menu present after you select the drop down. Play around with other elements. The fire_event method is the best way I know to make the drop down menu present.

Theming a node/add form in Drupal 6

I have a statement in my template.php file that directs to a custom node-myccktype.tpl.php. I've added some DIV's so that I can have a two column node/add form, but now I'm trying to find print my fields, but can't seem to get it.
I'm basically using something like this:
<?php print form_render($form['field_sr_minutes']); ?>
which I came across on a Drupal Blog, but I get call to undefined function "form_render"
I am using the var_dump to get the the array below, how can I print my node title(subject) field without printing everything else? This way I can put each form field in the column I want Instead of the standard vertical drupal form.
Array
(
[0] => Array
(
[#type] => textfield
[#title] => Subject
[#required] => 1
[#default_value] =>
[#maxlength] => 255
[#weight] => -5
[#post] => Array
(
)
[#programmed] =>
[#tree] =>
[#parents] => Array
(
[0] => title
)
[#array_parents] => Array
(
[0] => title
)
[#processed] => 1
[#description] =>
[#attributes] => Array
(
)
[#input] => 1
[#size] => 60
[#autocomplete_path] =>
[#process] => Array
(
[0] => form_expand_ahah
)
[#name] => title
[#id] => edit-title
[#value] =>
[#defaults_loaded] => 1
[#sorted] => 1
)
Sorry. Because of your .tpl file name I thought that you were trying to theme a node view. For forms, the right function is not form_render but drupal_render. You can basically write things like echo drupal_render($form['field_sr_minutes']) . In the very end, remember to do a drupal_render($form) to render all the remaining things which you have not rendered by hand. This will be required to have the form working correctly.
Old Answer
The node.tpl.php and other content
type specific .tpl.php get passed the
full node object in $node. Try doing
a
drupal_set_message(print_r($node,TRUE))
on top of your tpl file. From that you
can figure out the exact path of the
values you need to print.
For example, title of the node will be
available in $node->title. However you
should be careful to always use
check_plain if you are going to
print user submitted values. For CCK
fields, you can find the already
filtered values in $node-><field
name>[0][view].

Resources