Can't get to elements which there are in iframe of Customer.io - watir

I have Customer.io account for emails which collects emails from test server.
There in an iframe where there needed elements. But I can't get to them. If I use:
page.in_iframe(xpath: "//iframe[contains(#class, 'ember-view')]") do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
Then I get next error:
SyntaxError: (eval):1: syntax error, unexpected tIDENTIFIER, expecting ')'
.../iframe[contains(#class, 'ember-view')]').td(identifier)
... ^
(eval):1: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
...e[contains(#class, 'ember-view')]').td(identifier)
... ^
(eval):1: syntax error, unexpected ')', expecting end-of-input
...ntains(#class, 'ember-view')]').td(identifier)
...
And if I use this:
page.in_iframe(xpath: "//iframe[contains(#class, ember)]") do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
Then I don't get this error but element couldn't be found.

One of the goals of Watir is to never have to use XPath.
Consider rewriting your locator with regular expressions like this:
#browser.iframe(class: /ember/).td(text: /Order Confirmation/)

The problem appears to be with the parsing of the iframe XPath string. I do not understand why the interpreter is having problems, but here are some solutions:
For the first example, switch to using single quotes as the outer part of the String:
page.in_iframe(xpath: '//iframe[contains(#class, "ember-view")]') do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
For the second example, you do need to quote the attribute value. If you want to stick with double-quotes for the String, you can escape the inner double-quotes:
page.in_iframe(xpath: "//iframe[contains(#class, \"ember\")]") do |frame|
page.cell_element(xpath: "//td[contains(text(), 'Order Confirmation')]", frame: frame).when_present(30)
end
Alternatively, you might want to consider avoiding the XPath problem by using other locators:
page.in_iframe(class: 'ember-view') do |frame|
page.cell_element(text: /Order Confirmation/, frame: frame).when_present(30)
end

I've found another way:
#browser.iframe(xpath: "//iframe[contains(#class,'ember')]").td(xpath: "//td[contains(text(), 'Order Confirmation')]")
Because that examples don't want to work. Don't know why.
But thanks Justin:

Related

how can i manage this error? Mismatched input 'pair' expecting ')'

how can i manage this error? Mismatched input 'pair' expecting ')'.
I cannot remove all the brackets otherwise the message is not read by the binance api
strategy.entry ("RSILong", strategy.long , alert_message=" {"pair":"BTCUSDT","isBuy":true,"isSell":false,"isMarket":true,"isLimit":false,"isClose":false,"unitsPercent":"100","unitsType":"percentBalance","useTrailingStopLoss":false,"stopLossToBreakEven":false,"marginType":"ISOLATED","targets":[],"leverage":"125","closeCurrentPosition":true,"preventPyramiding":false,"reduceOnly":false,"limitPriceType":"fixedPrice","useDca":false,"dcaPercent":5,"token":"xxxxxxxx","exchange":"Binance-Futures","apiKey":"bin future"}" )
The quotes within the JSON string ({"pair":"BTCUSDT", ...) cause the mismatch.
Solution: Wrap the alert_message value in single quotes ' instead of double quotes ".
strategy.entry ("RSILong", strategy.long , alert_message='<your_json_string>' )

Why does it throw Invalid expression exception for Azure search

I receive this
Invalid expression: Syntax error at position 8 in '$filter=search.in(Categories, 'Career Resources', ',')'.
Parameter name: $filter
exception when performing a search in Azure.
Here is the code snippet by itself
$filter=search.in(Categories, 'Career Resources', ',')
Can anyone tell me why?
I ended up solving the problem by using a completely different syntax:
"Categories/any(f: f eq 'Career Resources')"
The search.in function got two overloads:
search.in(variable, valueList)
search.in(variable, valueList, delimiters)
so in you are case,
if you are searching for "Career Resources" then syntax will be
$filter=search.in(Categories, 'Career Resources')
And if you are searching for "Career" or "Resources" then syntax will be
$filter=search.in(Categories, 'Career,Resources' ',')

invalid input syntax for type numeric: " "

I'm getting this message in Redshift: invalid input syntax for type numeric: " " , even after trying to implement the advice found in SO.
I am trying to convert text to number.
In my inner join, I try to make sure that the text being processed is first converted to null when there is an empty string, like so:
nullif(trim(atl.original_pricev::text),'') as original_price
... I noticed from a related post on coalesce that you have to convert the value to text before you can try and nullif it.
Then in the outer join, I test to see that there's a limited set of acceptable characters and if this test is met I try to do the to_number conversion:
,case
when regexp_instr(trim(atl.original_price),'[^0-9.$,]')=0
then to_number(atl.original_price,'FM999999999D00')
else null
end as original_price2
At this point I get the above error and unfortunately I can't see the details in datagrip to get the offending value.
So my questions are:
I notice that there is an empty space in my error message:
invalid input syntax for type numeric: " " . Does this error have the exact same meaning as
invalid input syntax for type numeric:'' which is what I see in similar posts??
Of course: what am I doing wrong?
Thanks!
It's hard to know for sure without some data and the complete code to try and reproduce the example, but as some have mentioned in the comments the most likely cause is the to_number() function you are using.
In the earlier code fragment you are converting original_price to text (string) and then substituting an empty string ('') if the value is NULL. Calling the to_number() function on an empty string will give you the error described.
Without the full SQL statement it's not clear why you're putting the nullif() function around the original_price in the "inner join" or how whether the CASE statement is really in an outer join clause or one of the columns returned by the query. However you could perhaps alter the nullif() to substitute a value that can be converted to a number e.g. '0.00' instead of ''.
Sorry I couldn't share real data. I spent the weekend testing small sets to try and trap the error. I found that the error was caused by the input string having no numbers, which is permitted by my regex filter:
when regexp_instr(trim(atl.original_price),'[^0-9.$,]') .
I wrongly expected that a non numeric string like "$" would evaluate to NULL and then the to_number function would = NULL . But from experimenting it seems that it needs at least one number somewhere in the string. Otherwise it reduces the string argument to an empty string prior to running the to_number formatting and chokes.
For example select to_number(trim('$1'::text),'FM999999999999D00') will evaluate to 1 but select to_number(trim('$A'::text),'FM999999999999D00') will throw the empty string error.
My fix was to add an additional regex to my initial filter:
and regexp_instr(atl.original_price2,'[0-9]')>0 .
This ensures that at least one number will be in the string and after that the empty string error went away.
Hope my learning experience helps someone else.

DocumentDB Stored Procedure Lumenize

I'm using the aggregate stored procedure lumenize https://github.com/lmaccherone/documentdb-lumenize with the .net client and I'm in trouble in the filterquery content.
How simply pass alphanumeric value to the filterquery query ?
string configString = #"{
cubeConfig: {
groupBy: 'Modele',
field: 'Distance',
f: 'sum'
},
filterQuery: 'SELECT * FROM Modele WHERE ModeleGUID = ''0b93def1-ccd7-fc35-0475-b47c89137c3f'' '}";
Each test gives me a parse error in the filterquery :(
Error: One or more errors occurred.
Message: After parsing a value an unexpected character was encountered:
'. Path 'filterQuery', line 7, position 63.
End of demo, press any key to exit.
Thanks
Just to properly close this out: The issue is related to multiple single-quotes in the filter string. As long as they're escaped properly (e.g. \'), things should work as expected.

Can't access an element by a data- attribute with an underscore

Good day everyone!
I have an element
<tbody class="cp-ads-list__table-item _sas-offers-table__item cp-ads-list__table- item_state-deposit" data-card_id="16676514">
I'd like to access it by the data-card_id tag, but when I try the following
#browser.tbody(:data_card_id => "16676514").hover
I get an error
unable to locate element, using {:data_card_id=>"16676514", :tag_name=>"tbody"} (Watir::Exception::UnknownObjectException)
I guess my code would have worked if the tag were "data-card-id", but it's "data-card_id".
How do I access my element by this attribute?
Problem
You are right that the problem is the underscore in the data attribute. As seen in the ElementLocator, when building the XPath expression, all underscores are converted to dashes (in the else part of the statement):
def lhs_for(key)
case key
when :text, 'text'
'normalize-space()'
when :href
# TODO: change this behaviour?
'normalize-space(#href)'
when :type
# type attributes can be upper case - downcase them
# https://github.com/watir/watir-webdriver/issues/72
XpathSupport.downcase('#type')
else
"##{key.to_s.gsub("_", "-")}"
end
end
Solution - One-Off
If this is the only data attribute that is using underscores (rather than dashes), I would probably manually build the XPath or CSS expression.
#browser.tbody(:css => '[data-card_id="16676514"]').hover
Solution - Monkey Patch
If using underscores is a standard on the website, I would probably consider monkey patching the lhs_for method. You could monkey patch the method so that you only change the first underscore for data attributes:
module Watir
class ElementLocator
def lhs_for(key)
puts 'hi'
case key
when :text, 'text'
'normalize-space()'
when :href
# TODO: change this behaviour?
'normalize-space(#href)'
when :type
# type attributes can be upper case - downcase them
# https://github.com/watir/watir-webdriver/issues/72
XpathSupport.downcase('#type')
else
if key.to_s.start_with?('data')
"##{key.to_s.sub("_", "-")}"
else
"##{key.to_s.gsub("_", "-")}"
end
end
end
end
end
This would then allow your original code to work:
#browser.tbody(:data_card_id => "16676514").hover

Resources