Codeception can't click on element it has seen just before - html

Hello dear people of Stackoverflow,
currently I am writing acceptance tests with Codeception using Selenium as WebDriver module. In my test to check if our sub-navigation exists, is complete and works I struggle with the following piece of code:
$I->see('Partners');
$I->click('Partners');
all the see calls are working perfectly, but the click call fails with an ElementNotVisibleException stating that the element to be clicked is not visible, which I don't understand since the see call worked.
To make sure we're not seeing any old "Partners" string on the page but it really is the link I want to click, I changed the call by adding the a selector.
$I->see('Partners', 'a');
$I->click('Partners');
Still, I'm getting the ElementNotVisibleException from before. In the next step, I added a context to the click call to this:
$I->click('Partners', 'a');
Which made the exception disappear. Still, the click never happens, the test simply fails with the message:
Link or Button or CSS or XPath element with 'Partner' was not found.
I even used XPath in the click call like this: //a[text()='Partners'] and get the same message.
What bothers me the most with this is that the see call seems to see the link I am trying to click and moreover, even the page source and screenshot provided by Codeception after a fail contain this very link, visible and in valid HTML.
I tried to click on some other elements within the sub-navigation with the same result, while - which is even more strange - clicks on links in the main navigation seem to work just fine.
I have no idea why this doesn't work but any help is greatly appreciated.

I don't understand exactly why it happens in some cases and not others, but I've found a solution that works for me: Use CSS selectors only.
Basically in some cases (I think it has to do with clicking on div/span rather than a/button) ->see() will work with the fuzzy text string as first argument, but ->click() requires the explicit CSS selector.
So this will have the "I can see but not click" problems:
// BROKEN
$I->see("All topics", ".header-taxonomy .taxonomy-list-title");
$I->click("All topics", ".header-taxonomy .taxonomy-list-title");
But this will work:
// WORKS
$I->see("All topics", ".header-taxonomy .taxonomy-list-title");
$I->click(".header-taxonomy .taxonomy-list-title");
Obviously it's not ideal at all, partly because it requires a unique selector, but for me mostly just because it makes the tests and testing output less consistent and harder to read.
Either way, I just wanted to get this testing script finished, and now it's working, and because I'm still using ->see() with the fuzzy text locator, I'm still confident that the text is showing before I click.
Notably, this issue doesn't happen when using the PHPBrowser module, which is what tripped me up. I "upgraded" to WebDriver and found my scripts were broken in all these places due to the different behavior of ->click() (in addition to the expected need to open menus before using them, which wasn't needed in PHPBrowser)

Related

Why is VBA throwing Run Time Error 438 when using querySelector to click link on website?

I am trying to navigate through a website using a VBA macro. I have been successful so far adapting my code off of this answer, but have come upon a situation where I need to click on a "logout" link that does not have an ID or Name when I inspect it (for reference, see below:)
Through some searching, it seems that the preferred method to find and direct VBA to click on this link is using querySelector. I've found various similar questions (see here, here, here, and here) which direct how to use it.
As a test, I simply tried the below to see if it would work:
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
'log in, click on various elements here
Set logoutButton = ie.document.queryselector("*")
MsgBox logoutButton
Unfortunately, VBA throws Run Time Error 438 on the querySelector line, and I'm unable to understand what it is that I'm doing incorrectly.
I have added the following references to VBA:
Could someone let me know what it is I'm missing that's causing this error? Additionally, is this the method that I should be using to click the link?
Thanks!
EDIT: #QHarr has been helpful with finding out why I'm getting this issue: it's a problem with the emulation settings on Internet Explorer. querySelector will only work with document mode 9 and beyond, but my IE is defaulting to 8.
Even when I change the mode to 9 (and enable the Persist Emulation setting), it appears that my IE still opens with 8 and only changes to 9 when I check on the document mode. This causes me to still get the same error, unless I manually pause my code, check the document mode, then rerun the code.
querySelector will throw an exception if nothing is selected. Try right clicking the element and copying the css selector. Or you can write your own.
table.LoginDialog td > a:nth-child(2) might work.
It's worth setting a break point on the selector and testing them out in the Immediate window.

Chrome - type=file drag and drop

I have a weird situation. One of my users is using functionality of Chrome (current version, 49, 50), that he drags and drops a file from his folder on local computer to normal input type=file button in a form on the webpage. Once again, let me stress it even more, its normal html input, no fancy javascript, no drag&drop events and handlers, nothing like this. It just takes the name of the dragged file and puts it into the input field, as like he selected it via "normal" way, opening the file select window, locating file on harddrive, selecting the file and confirming.
In some specific situation, this stops working (while doing some edits in the page via javascript / ajax), and I need to "reenable" it.
But, and that is my question, I haven't found any documentation of this "feature" in Google Chrome (or maybe some other browsers as well, I don't know). Why it works, how it works, how it should work and what to do if it stops working :) Does anyone has any experience with this ? The only way how to "fix" it now is to reload the page. I'd love to solve it ... :)
EDIT 1 : I just did a quick test, it works and bugs the same way in Firefox on Win. It doesn't show any error in dev console or any message, it just doesn't add the file as expected.
I've found it. The previous discussion with deceze pointed me to test the javascripts I have on the page, that do not "interfere" with the input type=file ... they weren't any such scripts, but I've found that after doubleclick on the table (that I'm using for editing) this script is being called
$(document).bind('drop dragover', function (e) {
e.preventDefault();
});
and there wasn't any unbind action when table is saved ... this caused the drag and drop everywhere on the page to stop working after the edit.

Is there a maximum number of clicktag variables allowed in a banner ad?

So, this is pretty silly. I'm working on a banner ad that utilizes the clicktag. It's a surprisingly fancy one that uses pointroll, and when you hover over the 300x250 banner ad, it pulls up a larger one overtop of it that is bigger and much more interactive. In total, the larger banner has 29 clicktags, all using the variables "clickTag1" to "clickTag29".
The banners are all done, everything fires correctly (according to my trace statements). However, I'm in the middle of QA, testing all of the clicktags using this validator: https://flashval-temp.appspot.com/validator/ , when suddenly, it stops working after clickTag20. I thought it may have been the validator at first, so I tried other validators. No luck. I went back into my code (everything is a duplicate of one template, so the only code changes made were the changes to the string), and made sure to test it again. They're firing off just fine according to my trace statements.
Finally, and this doesn't seem to make sense to me, but I switched the variables clickTag20 and clickTag21. The button that fired off clickTag20 worked, so I assigned it clickTag21. The button that was assigned clickTag21 was the first to stop working, so I assigned it clickTag20. When I ran that through the validator, the button that was assigned to clickTag20, regardless of which button it was, worked! The one that was assigned clickTag21 never did, also regardless of which button it was fired off from.
The variable is a string of a paramObj. How does the content of that string matter? I would have assumed it was compile order, but even in that case, clickTag21 should have fired and not clickTag20. What is going on here? Has anyone else experienced this? If so, did you have a workaround? Please and thank you!!
Here is the thing... when you set a clicktag you're waiting for a flashvar. A parameter sent from the HTML to your SWF file. (more: http://helpx.adobe.com/flash/kb/pass-variables-swfs-flashvars.html)
Usually you'd test, if this parameter doesn't exists, the banner should do nothing, otherwise, open the link.
Turns out, and this is a guess, that these validators don't know how many clicktags you have in your flash file - or how many parameters you're waiting for - , so they pass up to 20 variables to your flash file, which is more than reasonable.
The bottom line is: if your events are working, you should be fine. Pointroll has a QA team, if something comes up, they will let you know, but as far as I can see from here, you should be fine.
Good luck

Selenium does not record Ajax Call. Need help on coding in html or selenese

I am recording a .Net application using Selenium IDE. Theres this scenario, that a textbox is presnt. I need to enter a name to search. As soon as i start typing, matching options come in a dropdown below. I have to select one of them, then the application goes to the next page.
The problem is, Selenium doesnt record this selection from the drop down. More over, when the script is typing in the name, the dropdown list is not being visible at all.. i.e. the ajax call is not occuring.
Please help. I need the solution code in Selenese or HTML, since I'm not much of a coder myself, and also, I am simply recording and playback, so I am not using Java or other scripts.
This question is great,
and so is the answer in this blog: http://blog.buberel.org/2010/07/howto-test-jquery-ajax-autocomplete-menus-with-selenium.html
other option to deal with this problem is to use a different way to insert your text into the text box, as described here: Can selenium handle autocomplete?

Selenium Chrome Webdriver stalls when trying to get_attribute('href')

I'm building a webcrawler using Selenium Webdriver with Chrome. It uses
links = self.browser.find_elements_by_xpath("//*[#href]")
gets all the links on a page and then loops through the links to filter them. However, on every site I've tested, once it gets to a certain link on a certain page, it stalls at this line:
url = link.get_attribute("href")
It's not an error, it just stops, as if it hit an unending loop. For a given site, it's always on the same link on the same page for every test run. The stalling does not occur with Firefox - everything works fine. However, I need it to do this using Chrome for other reasons (trust me on this).
The version of Chrome I'm using is 28.0.1500.52, and I'm using the latest Chrome driver, which is compatible with that version. What could be going on here?
EDIT (IGNORE THIS EDIT)
After looking into it some more, I've found what's causing the problem: There's a part further down in the code that mouses over every link that's found.
hov = ActionChains(self.browser).move_to_element(link)
hov.perform()
When I comment that part out, it works. Now I have to figure out why this should have any effect on getting the href attribute from a Selenium link object (especially when it works fine for the first arbitrary number of link objects)...
EDIT 2
Ignore the first edit.