amp-bind Error: Default value for [variable] does not match first expression result - google-amp

I am using amp-bind to bind the class attribute:
<div [class]="menu.menuClass" class=hide">...</div>
with the following amp-state element:
<amp-state id="menu">
<script type="application/json">
{"menuClass":"hide"}
</script>
</amp-state>
However, after the page loads, I get the error:
amp-bind: Default value for [class] does not match first expression result (hide). This can result in unexpected behavior after the next state change.​​​
(this error is empedded in the div itself)
As you can see, my default value does match the first expression. What am I doing wrong?

Ah, this is a bug! :) I've filed this issue and we're working on a fix.
We try to keep an eye on StackOverflow but feel free to file an issue in our GitHub project or ask a question on our Slack channel next time. Thanks for raising this, Gil.

Related

Is there a way to use xpath to search for a value where a part of the value dynamically changes?

I’m trying to match a value where I don’t necessarily know the whole value every time i.e. it's randomly generated. Is there a way to search for a value where a part of the value dynamically changes?
Please see my example of value I'm trying to find and my attempted xPath:
<div class="target" testid="target”>
<h2>Hi, random user</h2>
<p>To get the xpath <b>target</b> of <b>[text I don’t know]</b> in <b>[text I don’t know]</b>, you need to do the following</p>
</div>
I’ve tried the following xpath I picked up from another question but it don’t get a match:
//p[matches(.,'^To get the xpath <b>target</b> of <b>.*</b> in <b>.*</b>, you need to do the following$')]
I’ve tried different combinations with and without the bold tag but can’t seem to get it to match. truthfully I'm not sure I've got the right syntax...
Try the plain text in the second argument of matches e.g.
//p[matches(., '^To get the xpath target of .*? in .*?, you need to do the following$')]
Online sample here.
Why not to use contains() method using the fixed attribute value?
Something like:
//p[contains(.,'you need to do the following')]

Ruby Capybara Element not found error handling

internet.find(:xpath, '/html/body/div[1]/div[10]/div[2]/div[2]/div[1]/div[1]/div[1]/div[5]/div/div[2]/a').text
I am looping through a series of pages and sometimes this xpath will not be available. How do I continue to the next url instead of throwing an error and stopping the program? Thanks.
First, stop using xpaths like that - they're going to be ultra-fragile and horrendous to read. Without seeing the HTML I can't give you a better one - but at least part way along there has to be an element with an id you can target instead.
Next, you could catch the exception returned from find and ignore it or better yet you could check if page has the element first
if internet.has_xpath?(...)
internet.find(:xpath, ...).text
...
else
... whatever you want to do when it's not on the page
end
As an alternative to accepted answer you could consider #first method that accepts count argument as the number of expected matches or null to allow empty results as well
internet.first(:xpath, ..., count: nil)&.text
That returns element's text if one's found and nil otherwise. And there's no need to ignore rescued exception
See Capybara docs

Getting this message app.js:33 Uncaught TypeError: Cannot read property 'appendChild' of null at HTMLButtonElement.addTodo

enter image description here
enter image description here
I had to initially put the behind the body because it was refreshing the page.
Now i'm running into this error "app.js:33 Uncaught TypeError: Cannot read property 'appendChild' of null
at HTMLButtonElement.addTodo"
Your selector is .todo-List, yet all your other class names don't use any upper-case characters, and your HTML shows class="todo-list" (list, not List!) as well.
So, I'd assume that this is a typo and should actually be todo-list with lower-case l, so you should change the line 4 to const todoList = document.querySelector('.todo-list').
The fact that you asked about the "message" of Cannot read property "appendChild" of null though sounds to me as if you didn't understand the error message. Please take the time to review this article and take a quick squiz at how to use a debugger. Especially the latter is a tremendously important skill that will help you trace back those issues yourself. I'm sure, had you realized that the issues comes from line 4, you'd eventually have discovered that the selector is wrong.

JMeter issues with span tag in Response Assertion

I added a Response Assertion to my test to hit the home page of our local site. I added this to the "Patterns to Test" in a Response Assertion:
Email
This worked. ( To get that label, I did View Source in Firefox and copied the code including all white space. I then clicked "Add" for the Response Assertion and pasted the copied code directly into JMeter this way. ) When I run my test, my test will pass with just this label as a Pattern to Test. It shows no red errors after running it in JMeter.
However, when I add the following span tag by clicking on "Add" to get a new entry in the same Response Assertion, the test will fail.
1.7.0.147
So, to be clear, I had 2 entries for the same Response Assertion...one for the "Email" label and one for the "footerVer" span. Each of these had their own separate line under the same Response Assertion.
Also, for most tests that passed and did not pass, I had "Main Sample only", "Text Response", and "Contains" selected. I did try to change to "Matches" and "Equals" but I just ended up with different errors. So, I wanted to stay on "Contains" for now since my other entry for the "Email" label worked when I had "Contains" selected.
Under the "View Results Tree", JMeter tells me about this failure when I add the span tag:
Assertion error: false
Assertion failure: true
Assertion failure message: Test failed: text expected to contain /
1.7.0.147
/
I also have had success with other tags like , , , , etc. along the way.
Only the tag seems to be giving me a problem right now. Any ideas?
===============================
Added config:
I am not able to add the full response since it is not my code, but the company's code. But, I can try to get something on here that me be useful in a different way.
This is the response dealing with the version copied verbatim from the response tab within JMeter:
<span class="footerVer">
1.7.0.147
</span>
Hope that helps
I would suggest using XPath assertions for multiline HTML entities parsing as page source may vary and it can be a headache to deal with flaky HTML code.
Following XPath expression validates whether inner text of span with footerVer class equals 1.7.0.147
//span[#class='footerVer']/text()='1.7.0.147'
Use Substring instead of Contains for Pattern Matching rules:
http://jmeter.apache.org/usermanual/component_reference.html#Response_Assertion
So, I found one way around this. Although, I do not think this is the most efficient way to verify the test. I split the span into 3 individual lines in the Response Assertion.
<span class="copyright marginLeft_100">
© Copyright 2002-2013 Turning Technologies, LLC. All Rights Reserved.
</span>
==========================
I do not really mind the first 2 lines. But, the third line is so generic it really does no good if not combined with the beginning tag
Well, for now, I can at least confirm something. Also, I left it on "Contains", even though I took a look at the other link posted above, because all of my other tags presented no problem when it was on "Contains". Hope this helps someone else also.

using xpath in selenium.get.Text and selenium.click

I have Адреса магазинов on page and want to store text, then click on this link and verify that the page where am I going to contains this text in headers. So I tried to find element by xpath, and selenium.getText get the right result, but selenium.click goes to another link. Where have I made a mistake? Thanks in advance!
String m_1 = selenium.getText("xpath=html/body/div[3]/div[2]/div[1]/h4[1]");
selenium.click("xpath=html/body/div[3]/div[2]/div[1]/h4[1]");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.getText("css=h3").contains(m_1));
page:http://www.svyaznoy.ru/map/
Resume:
using xpath=//descendant::a[#href='/address_shops/'][2] or css=div.deff_one_column a[href='/address_shops/'] get right results
using xpath=//a[#href='/address_shops/'] - Element is not currently visible
xpath=//a[#href='/address_shops/'][2] - Element not found
There is a missing slash at the beginning of the expression. I am kind of surprised this got through at all - the first slash means "begin at root node".
Also, it is better to select the <a> element instead of the <h>. Sometimes it works, sometimes is misclicks, sometimes the click doesn't do anything at all. Try to be as concrete as you can be.
Try this one.
String m1 = selenium.getText("xpath=/html/body/div[3]/div[2]/div/h4/a");
selenium.click("xpath=/html/body/div[3]/div[2]/div/h4/a");
selenium.waitForPageToLoad("30000");
// your variable is named m1, but m_1 was used here
assertTrue(selenium.getText("css=h3").contains(m1));
By the way, there are even better XPath expressions you could use. See the documentation, it really is helpful. Just an example, this would work, too, and is much easier to write and read:
String m1 = selenium.getText("xpath=//a[#href='/address_shops/']");
selenium.click("xpath=//a[#href='/address_shops/']");
Sorry, didn't notice page link. Css for second link can be something like that css=div.deff_one_column a[href='/address_shops/']

Resources