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.
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