This is very similar to: adding php variable into Xpath But slightly different...
What I'm trying to do is this:
$status = "Test!";
//ajax request to update the page
$this->postToPage($status);
//This is the part that is failing..
$this->waitUntil(function ()
{
if ($this->byXPath("//span[contains(text(),'{$status}')]"))
{
return true;
}
return null;
}, 20000);
$elementtext = $this->byXpath("//span[contains(text(),'{$status}')]")->text();
$this->assertEquals($status, $elementtext);
Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -'Test!' +'Test!.'
Any idea why $elementtext is being set to "Test!." with the dot on the end? I've come to a stalemate here and have no idea why on earth it is appending the dot.
I found my issue.
It's because postToPage() is inputting its contents into another span element, and therefore, my waitUntil() referred to that to continue, rather than the newly created span. my assert also was still grabbing the in regards to postToPage() as well.
来源:https://stackoverflow.com/questions/31999509/xpath-assertion-failure-with-dynamic-xpath