Selenium RC: How to assert an element contains text and any number of other elements?
Posted
by Andrew
on Stack Overflow
See other posts from Stack Overflow
or by Andrew
Published on 2010-06-03T16:37:43Z
Indexed on
2010/06/03
17:34 UTC
Read the original article
Hit count: 273
I am using Selenium RC and the PHPUnit Selenium Extension. I am trying to assert that a table row exists, with the content that I expect, while making it flexible enough to be reused.
Thanks to this article, I figured out a way to select the table row, asserting that it contains all the text that I expect.
$this->assertElementPresent("css=tr:contains(\"$text1\"):contains(\"$text2\")");
But now I would like to assert that a specific radio button appears in the table row also. Here's the element that I would like to assert that is within the table row. (I am currently asserting that it exists using XPath. I'm sure I could do the same using CSS).
$this->assertElementPresent("//input[@type='radio'][@name='Contact_ID'][@value='$contactId']");
Currently I have a function that can assert that a table row exists which contains any number of texts, but I would like to add the ability to specify any number of elements and have it assert that the table row contains them. How can I achieve this?
/**
* Provides the ability to assert that all of the text appear in the same table row.
* @param array $texts
*/
public function assertTextPresentInTableRow(array $texts)
{
$locator = 'css=tr';
foreach ($texts as $text) {
$locator .= ":contains(\"$text\")";
}
$this->assertElementPresent($locator);
}
© Stack Overflow or respective owner