How to know which element receives the click()? - selenium-webdriver

I am writing a script that goes to an Amazon URL and clicks on the 'Buy Now' button. That's it. I have to use WebdriverIO, javascript, and ChromeDriver. The problem is that I can't get this button to be clicked no matter which selector I use. I am able to manually do it just fine. But in the Code Inspect below, every combination of div/id/name, span/id/close, or input/id/name has resulted in no clicks. I know the script can see that web object because when I do a BuyNow.getText() to console, it prints out 'Buy Now'. And I know the xpath I use is good because I paste it into Inspect/Find and the exact element lights up yellow. Oh and the .click(), even though Visual Studio Code flags as deprecated, works just fine in previous scripts.
When I manually click on a button, is there a way to see what was the exact element that received this click?
let BuyNow = $(<XPATH>)
BuyNow.click()
Code Inspect

Ok so I found out what the problem was. It had nothing to do with my XPATH selectors, any one of which to the elements in the Code Inspect picture would have worked (example: let BuyNow = *[id='buy-now-button']). The issue is that in the WDIO config file, I had a custom Chrome Profile being used. Which is fine, the Chrome.exe I was using was pointing to another custom Chrome Profile. I thought these two were the same, but the folders paths were getting messed up. Once I resolved them, and had both the Chrome.Exe and WDIO config pointing to the same customer folder, Chrome started to allow me to select buttons. I think that the WDIO code was looking at one user profile of chrome, and the desktop chrome browser that I was using was another user profile.
Solved. Fun Stuff but not really.

Related

"WebExtension::executeScript: content script injected VM149:1" in Chrome loading React app

Haven't come across this message in all our testing and not sure if it is related to the actual issue.
Basically, have a user agreement text box that the user has to "read" (scroll to the bottom of) before they can click the box that they agree to it. Pretty standard stuff. We launched the web app Sunday and of about 100 users, two have stated that even though they scrolled to the bottom of the text box, the box did not become clickable.
The first one never got back to me, but the second user did and sent me a screenshot of the console:
WebExtension::executeScript: content script injected VM149:1
They are indeed scrolling to the bottom of the box. Initially, we just thought they were scrolling to the bottom of the page and they thought that is what they needed to do. But we were wrong.
I can't find much on it. Not even sure if it is related to the issue since it wasn't labeled as an error.
Both users are using Chrome latest version on Windows. We have them try Edge or Firefox and it works fine. Seems to be isolated to Chrome.
This is likely to be the Okta browser plugin. I have it installed and it produces this same error. The source of the plugin script is:
(function(code) {
if (eval("typeof Okta === 'undefined'")) {
eval("window.Okta = {};");
eval(code);
console.log("WebExtension::executeScript: content script injected")
} else {
console.log("WebExtension::executeScript: skipping eval script")
}
}
)(" /* A LOT OF MINIFIED CODE HERE */ ");

Angular and Google tag manager (GTM) gtm.click

I am running into a problem, and I cannot seem to find a fix for it. The situation is as follows the marketing department wants to integrate GTM. Which is fine as they want to have full control over the different third party providers they wish to integrate. But for this to happen they would like to have the ability to track all clicks on a page.
And they came back to me that currently no click events are being tracked with the current configuration within GTM. At first the thought was that events were not propagating (bubbling) upwards. But having tested this myself by binding a event listener to the document (click) (see below) all div, buttons etc. with an ng-click directives did reach this handler without problems.
document.addEventListener("click", function(event){
console.dir(event.target);
});
So my assumption was that there was something wrong with the configuration but after looking at the configuration (one I created myself which looks as follows):
I still could not get it to work. Buttons that already use angulartics - https://luisfarzati.github.io/angulartics/ to send an event to the GTM container work as expected:
Download
Only the catch all click events (or any filter on it like purely looking at button clicks) does not. Now after looking at it a little more it seems GTM expects the gtm.click _event to happen. But I can't figure out (gazing through the gtm.js file) how they bind to all click events within the document (there is a click binding on the document after initialization but I am unsure if this is GTM or something from angular). And even if so I have placed many breakpoints within this file which seemingly could be related to it but none of them triggered when something was clicked.
So my question is, has anybody got experience combining angularjs with angulartics and GTM while having it catch all click/touch/mousedown etc. events and send these to GTM?
Make sure that you pusblished GTM container after you made some changes. Use "Publish Now" or "Preview and Debug" buttons inside of GTM interface(top-right corner).
Because according to your tag config this tag should fire every time when user clicks something on the website.
Regarding to "gtm.click" - this GTM-event will fire every time, when user clicks something on the website.
On the screenshot you may see, how it looks like in GTM debug mode("Preview and Debug") when user clicking on somethig at web-page, when GTM click listener turned on(like in your tag).
May be some relevant articles from my website about tracking of buttons/links on GTM will help you too:
http://konygin.net/gtm/tracking-links-en/
http://konygin.net/gtm/tracking-buttons-en/
My problem turned out to be that the person (from marketing) who gave me the html GTM tags (noscript / script) did not copy it properly (or something went wrong when it was pasted within JIRA). And after I copied it directly (having gotten access to the GTM admin panel) it worked as I would expect it to work.
Seeing as I debugged it by trying to only have one index.html with purely a button in it. Even at that point the tracker did not work and I became suspicious why that was happening as there was no angular code any more that could cause the problems.
Lesson learned, next time copy code yourself when you need it to make sure it does not get corrupted along the way :/

How to use Selenium WebDriver to find Firefox add-ons warning dialog

I am testing downloading and installing an add-on that our company makes. I can add the domain to the Firefox profile whitelist to eliminate the first dialog, but then FF displays a second one that says "Install add-ons only from authors whom you trust". I can't find a way for Selenium to find it. It's the one that looks like this:
I have tried driver.switchTo().alert().accept() - this is not an alert.
I have tried driver.switchTo().findElement(linkText("Install") - nothing found.
I have tried using SikuliWebDriver to find an element by location (picking some random ints to work off of) and then just send keys like Keys.TAB and Keys.ENTER, but as I step through in debug mode, driver.findELementByLocation(20,40) never returns.
I have tried driver.getKeyboard().sendKeys(Keys.TAB) (sending two tabs and an enter). Also never returns.
I think this dialog is generated by Javascript but I am unable to find out what JS generates it. Ideally I could find a name or an id for the button in the dialog and then use JavascriptExecutor to run the command. But without any kind of handle I'm stuck.
Any ideas?
Selenium can only see the DOM (document object model). It can't test desktop applications. The dialog shown is part of the Firefox application and not part of the DOM, so Selenium can't see or access or interact with it. Sad but true. Try Ranorex?

Issue in clicking on the browse button with selenium in IE

I am Clicking on the browse button in IE using Selenium Webdriver code in an upload file utility by reading the co-ordinates of the browse text. Whlie the code works fine in some machines in IE and firefox both, in yet another machine the same code is working for firefoxx but the browse button becomes unclickable in IE. We checked the settings in internet options, everything looks alike in both machines.
Please let us know if anyone faced any such issue and the resolution that could work.
If there is any other way to upload the file in your app by avoiding the "Browser" button method, then that is always preferred. Some people will use Apache HTTPComponents to do a POST upload to the servlet that the "Browse" button refers to. That is by far the preferred method rather than using WebDriver. The problem with the Browse button is that it opens native OS controls ( in some cases) and the only way you can control those is by using the Sikuli API to click on elements based on finding them with matching screenshots. Also, if you use Sikuli, you can't run multiple browser tests on the same machine since each test will block screen comparisons of another test and that will rule you out of using RemoteWebDriver.

Silverlight UI Automation issue - element cannot be found

I need to create automated tests for a Silverlight application, I use the System.Windows.Automation namespace. My problem is the following:
I use AutomationElement.FindFirst to locate UI elements in the UI tree:
AutomationElement toBeInvoked = browser.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.AutomationIdProperty, id));
This works for a few steps, but after it won't find anything. I inspected that after screen changes the UI tree is going to be empty, UISpy sees only the Silverlight control, but nothing more: screenshot
. (I've also tried to use TreeWalker, but the result was the same.) If I click manually, and inspect the elements with UISpy, everything is OK. But when I run my code, it stops (usually at the same button).
Later I realized that if I click through manually the screens that my code will visit, and after I run it, there won't be any issue... Strange. I tried it in FF 3.6, 4.0 and IE8. The problem is the same in every browser.
Has anyone any idea what could be wrong, or where could be the mistake? Am I missed something in my code, or the problem is in the settings of the browser?
Thanks in advance, regards,
Miklos
"If I click manually, and inspect the elements with UISpy, everything is OK. But when I run my code, it stops"
You can simulate manual-click this trouble-causing button by:
1.Get the coordinate of the button you want click by UI Automation;
2.Drive your mouse to click on its coordinate(by win32 mouse_event api);
See that if its following steps can run or not.

Resources