Codeception: Check a checkbox without ID in multiple rows - yii2 Codeception

Created on 21 Apr 2017  路  7Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

Click a Checkbox against a record and then delete the selected record in yii2 using codeception testing enviroment

What do you get instead?

Fail Checkbox or Radio by Label or CSS or XPath element with '#message-grid > table > tbody > tr > td:nth-child(1) > input[type="checkbox"]' was not found.

or
Fail Link or Button or CSS or XPath element with '//*[@data-key="1"]/td[@class="text-center"]/input[@type="checkbox" and @value="1"]' was not found.

Here is my Error Log:

1) MessageCest: Sent_mark un read with selection
 Test  tests/acceptance/models/MessageCest.php:Sent_MarkUnReadWithSelection
 Step  Click "//*[@data-key="1"]/td[@class="text-center"]/input[@type="checkbox" and @value="1"]"
 Fail  Link or Button or CSS or XPath element with '//*[@data-key="1"]/td[@class="text-center"]/input[@type="checkbox" and @value="1"]' was not found.

Scenario Steps:

 8. $I->click("//*[@data-key="1"]/td[@class="text-center"]/input[@type="checkbox" and @value="1"]") at tests/acceptance/models/MessageCest.php:162
 7. $I->wait(3) at tests/acceptance/models/MessageCest.php:33
 6. $I->dontSee("Incorrect username or password") at tests/acceptance/models/MessageCest.php:31
 5. $I->click(".btn-success") at tests/acceptance/models/MessageCest.php:30
 4. $I->fillField("#loginform-password","offneo123") at tests/acceptance/models/MessageCest.php:26
 3. $I->fillField("#loginform-username","admin1") at tests/acceptance/models/MessageCest.php:25


FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

Here is my MessageCest class method:

public function Sent_MarkUnReadWithSelection(AcceptanceTester $I)
    {
        $idmessage = 1;
        $xPath_Checkbox = '//*[@data-key="'. $idmessage .'"]/td[@class="text-center"]/input[@type="checkbox" and @value="'. $idmessage .'"]';

//         $selector = '#message-grid > table > tbody > tr > td:nth-child(1) > input[type="checkbox"]';
//         $I->see('//*[@data-key="1" and @class="unread"]')
        $I->click($xPath_Checkbox);
        $I->click('a#mark-unread');

    }

Details

  • Codeception version: 2.2.9
  • PHP Version: > 5.4
  • Operating System: Linux
  • Installation type: Composer
class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver
        - Yii2:
           part:
              [init, orm]
    config:
        WebDriver:
            url: 'http://localhost/TestProject/'
            browser: phantomjs
            window_size: 1920x1310
            capabilities:
              webStorageEnabled: true

WebDriver Yii

All 7 comments

Are you sure that your xpath locator is correct?

yes.
I opened the inspector in chrome and then right clicked on elemn and copied its xpath and selector and pasted in my code.

Please provide enough HTML code to reproduce your issue.

I didn't understand what are you asking.
I have provided the test function code.

Here is the HTML code of my webpage in (browser - inspect element)

<tr class="unread" data-key="1"><td class="text-center"><input type="checkbox" name="selection[]" value="1"></td><td class="open-view">admin1</td><td class="text-center open-view"></td><td class="open-view">Subject of Message</td><td class="open-view">2017-10-12 12:14:16</td><td class="action-column"><a id="view-btn" class="btn btn-sm btn-info" href="/OINTRANET/index-test.php?r=oinbox%2Fmessage%2Fview&amp;id=1" title="" aria-label="View" data-pjax="0" data-toggle="tooltip" data-original-title="View"><i class="glyphicon glyphicon-eye-open"></i></a> <a id="delete-btn" class="btn btn-sm btn-danger" href="/OINTRANET/index-test.php?r=oinbox%2Fmessage%2Ftrash&amp;id=1" title="" aria-label="Delete" data-confirm="Are you sure you want to delete this item?" data-method="post" data-pjax="0" data-toggle="tooltip" data-original-title="Delete"><i class="glyphicon glyphicon-trash"></i></a></td></tr>

xPath for the check box is:
//*[@data-key="1"]/td[@class="text-center"]/input[@type="checkbox" and @value="1"]
selector for checkbox is:
````

message-grid > table > tbody > tr > td:nth-child(1) > input[type="checkbox"]

````

I will take a look at your issue this weekend.

@ahmednawazbutt you used a wrong method - click opens links and submits forms, use checkOption to tick a checkbox.

Thank you @Naktibalda .
I tried that before, dont know what happened but now its working fine.

Still thank you very much. Appreciate your help

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joshhornby picture joshhornby  路  3Comments

sasha-x picture sasha-x  路  3Comments

allen0817 picture allen0817  路  3Comments

centerax picture centerax  路  4Comments

rogoit picture rogoit  路  3Comments