.click() with no id - how to activate click in test script ?

131 views
Skip to first unread message

Zk W

unread,
Dec 8, 2014, 12:49:57 PM12/8/14
to dal...@googlegroups.com
Hi All

We have a logout link with no id attribute.
How can we pass this parameter in dalekjs test script ?
We wanted to use .click method.

<a href="/path/to/a/link">Logout</a>

thanks

asciidisco

unread,
Dec 8, 2014, 12:57:14 PM12/8/14
to dal...@googlegroups.com
You can use any valid CSS selector (that is support by the Browser you´re testing in) to query elements: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

It is supported in IE since version 7.

Zk W

unread,
Dec 8, 2014, 1:38:01 PM12/8/14
to dal...@googlegroups.com
Hi Sebastian

We're using chrome to begin our first test.
We can find the element but it doesnt have the id attribute which dalekjs requires to perform its action.
If you think we're wrong, could you provide a simple example on how we can invoke in dalekjs script with (case 1) no id attribute or (case 2) perhaps a name attribute present

Thank you

asciidisco

unread,
Dec 8, 2014, 2:12:17 PM12/8/14
to dal...@googlegroups.com
Hi,

your example could be tackled like this: .click('a[href="/path/to/a/link"]')
And it isn't correct that Dalek requires id attributes, as I have written in the post before, Dalek can get along with any valid CSS selector (supported by the browser the tests run against).

Maybe you could get some help from your development department when it comes down to questions like this. 

Zk W

unread,
Dec 8, 2014, 2:12:36 PM12/8/14
to dal...@googlegroups.com
Hi Sebastian

We copy the xpath of that link with Google developer tool GUI in the xpath below but it doesnt seem to find the element.
We double-checked the element's path.
Can you confirm .click would work in this situation ?

.click(test.xpath('/html/body/div/div[1]/div[3]/div[2]/a[3]')) 
.assert.url('/path/to/a/link')

Thanks


On Monday, December 8, 2014 9:57:14 AM UTC-8, asciidisco wrote:

Zk W

unread,
Dec 8, 2014, 9:37:49 PM12/8/14
to dal...@googlegroups.com
Hi Sebastian

Thanks for your response. Your suggestion works. Still unclear why the xpath didnt work.
We follow your documentation closely.
We don't have engineering team to consult.

We have a form post with no id.

<form action="https://host.com/cgi-bin/check" method="POST" name="_ABC"></form>
<tbody>
<tr>
<td align="center">
                <input type="submit" class="btn" name="submit" value="ABC">
                <input type="hidden" name="login" id="login" value="qq">
                </td>
</tr>
        :
:    
</tbody>


Is .click() or .submit() the right way to submit the form ?
.click(test.xpath('/html/body/table/tbody/tr[3]/td[1]/table[1]/tbody/tr[1]/td/input[1]')) 
or
.submit()    (how do we reference the element in .submit()) ?

Thank you.

asciidisco

unread,
Dec 10, 2014, 5:05:48 AM12/10/14
to dal...@googlegroups.com
Hi,

hmm, if you do not have access to development resources (assuming that you´re a pure Q&A team), maybe DalekJS isn't the right tool for you.

Regarding your question, as stated in this issue, XPath is not yet supported: https://github.com/dalekjs/dalek/issues/3
If you plan to go further with DalekJS, I highly recommend to gain some knowledge about CSS Selectors (they are quite powerful) - MDN would be the best page to start: https://developer.mozilla.org/en/docs/Web/CSS

Dalek has no `.submit()` method out of a simple reason: It tries to mimic the real world usage of your page & I bet less than 1% of your users would submit the form using the DevTools and JavaScript,
more than 99% will probably click on the submit button. A suitable CSS selector for your scenario would be:  `.click('form[name="_ABC"] input[type="submit"]')`

Regards
Reply all
Reply to author
Forward
0 new messages