0

I'm Writing a Selenium text case for an ASPX page. I want to click this ASP.NET asp:LinkButton element:

<asp:LinkButton runat="server" OnClick="Test_Click" Text="Just try to click me" ID="testtest123"></asp:LinkButton>

Which appears like this in the HTML page generated by .NET:

<a id="testtest123" href="javascript:__doPostBack(&#39;testtest123&#39;,&#39;&#39;)">Just try to click me</a>

But while Selenium has no problem finding the element, the Click() does nothing. I get no element missing exceptions or timeouts, the testcase just runs on as if the click fired properly.

Here's the simple line for clicking the element;

Browser.Driver.FindElement(By.Id("testtest123")).Click();

This code works fine with other ASP elements such as buttons and text boxes. I use C# to write my test cases using the 64 bit webdriver and IE 11.

I researched the solutions here: ASP.Net LinkButton Prevent Postback Not Working - JavaScript but they do not seem to apply to my situation:

Any help would be greatly appreciated!

EDIT: I posted another thread about the issue on this website: https://code.google.com/p/selenium/issues/detail?id=7846&can=8&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary

Community
  • 1
  • 1
user1531921
  • 1,372
  • 4
  • 18
  • 36
  • Have you tried the 32bit Firefox driver to rule out a Selenium bug? – Alexander Sep 05 '14 at 10:54
  • So what does your test case do after clicking that `LinkButton`? – mostruash Sep 05 '14 at 10:59
  • It tries to click another button which is displayed by the above linkbutton. – user1531921 Sep 05 '14 at 11:12
  • The thing is, the problem is that Selenium doesn't click the linkbutton itself. I've isolated that part of the test case and it's obvious that the button isn't clicked properly. Something goes wrong when Selenium fires that Click() method when it comes to asp:linkbutton specifically. – user1531921 Sep 05 '14 at 11:13
  • I've tried a workaround by calling the generated javascript postback function directly, but I just get a javascript error. – user1531921 Sep 11 '14 at 11:01

3 Answers3

0

I had a similar problem where some controls were rendered as espected and other don't, so are you sure the link ID is "testtest123"?

You have to set Client ID Mode to static in order to make the HTML ID be the same as in the .NET (the default is inherit, but in the web.config it is generlly set to be AutoID).

<asp:LinkButton runat="server" OnClick="Test_Click" Text="Just try to click me" ID="testtest123" ClientIDMode ="Static"></asp:LinkButton>
MVCDS
  • 380
  • 4
  • 14
0

If the rendered HTML is actually <A id=testtest123 then that is not valid HTML since the attribute does not have quotation marks around the value. If this is actual value then the problem is further upstream than Selenium

0

One possibility is that selenium is correctly clicking the element, but that the linkbutton's javascript code is not executing quickly enough for the rest of your test. This is because when selenium encounters an <input type="submit"> tag (like asp.net button controls), it knows that it has to wait for the form submission before going to the next test step. However, a linkbutton is just an <a> tag, and worse, it has javascript as the href as opposed to a url. So it's possible that the postback javascript takes 50 milliseconds to execute or whatever, in that case, it's possible a test like this:

step n: click linkbutton - selenium does not know how long this takes so proceeds to next step

step n+1: click some button - if this happens before the js finishes executing, it would be like step n did not happen at all

This is plausible in the case of selenium because it operates at the speed of a program, whereas a human tester would never be able to click the next step quickly enough to cause such a problem. The fix for this is to add a delay step, or, to add a watch step on a javascript variable that you set on click of your linkbutton.

Edit:

Ok, so then this is not the issue. I'm almost positive it has something to do with the javascript in the href, though, so could you try the answer here: https://stackoverflow.com/a/18847713/1981387 ?

Community
  • 1
  • 1
welegan
  • 3,013
  • 3
  • 15
  • 20
  • There is no next step. This use case only attempts to click the linkbutton (that one line of code) and I manually verify by looking at the page that nothing happens. – user1531921 Sep 06 '14 at 17:15