This problem might be caused by two things
1. The DOM is not ready yet when you attached the listener
2. Your HTML code is added dynamically
The solution for the first case is to put your code under the ready block
$(document).ready(function(){
$('.pinterest-button').click(function() {
$('.pinterest-button').hide();
$('#pin1 a img').click();
setTimeout("$('.pinterest-button').show();", 1000);
});
});
The solution for the 2nd case is to make the listener live for any changes
$(document).ready(function(){
$('.pinterest-button').on('click',function() {
$('.pinterest-button').hide();
$('#pin1 a img').click();
setTimeout("$('.pinterest-button').show();", 1000);
});
});
and add the on click to your image listener if needed
I hope this can help
Answer from Seder on Stack OverflowThis problem might be caused by two things
1. The DOM is not ready yet when you attached the listener
2. Your HTML code is added dynamically
The solution for the first case is to put your code under the ready block
$(document).ready(function(){
$('.pinterest-button').click(function() {
$('.pinterest-button').hide();
$('#pin1 a img').click();
setTimeout("$('.pinterest-button').show();", 1000);
});
});
The solution for the 2nd case is to make the listener live for any changes
$(document).ready(function(){
$('.pinterest-button').on('click',function() {
$('.pinterest-button').hide();
$('#pin1 a img').click();
setTimeout("$('.pinterest-button').show();", 1000);
});
});
and add the on click to your image listener if needed
I hope this can help
I think this is most like an issue related to Safari itself:
https://github.com/webdriverio/webdriverio/issues/4565
keyboard - Command + Click not opening links in new tabs - Ask Different
Command + tap-to-click not working proper… - Apple Community
macos - Some click dont work in Safari browser using selenium standalone server - Stack Overflow
SafariDriver click on a button not working with safari 13.0.1
The click event resulting from a tap on iOS will bubble as expected under just certain conditions -- one of which you mentioned, the cursor style. Here is another:
The target element, or any of its ancestors up to but not including the
<body>, has an explicit event handler set for any of the mouse events. This event handler may be an empty function.
http://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
This is much better fix vector, and can be done without a browser check. You do have to add an extra div due to the "not including the <body>" part:
<body>
<div onclick="void(0);">
<!-- ... all your normal body content ... -->
</div>
</body>
Now every click event originating inside that div will bubble as expected in iOS (meaning you can catch them with $(document).on('click', '.class', etc...)).
Have you tried this?? This is because ios doesn't fire the click event sometimes, only recognizes the touch event
$(document).on('touchstart click', [Selector], [ Event ]
While many people might have another keyboard hooked up to their computer, that wasn't the case for me. You can be sure by disabling bluetooth (if your main keyboard is wired).
Other problems I've researched include: specific websites mess with CMD+Click via javascript either intentionally or accidentally. To debug, try a few different websites. If it's just one website that you really want CMD+Click to work on, there are some chrome extensions you can try, I haven't used any of them.
Make sure your CMD key works correctly. The OP in this thread did this via using CMD+0 or CMD+1 to navigate to different tabs.
Not sure what my issue was, but restarting the OS fixed it. Give that a try. Good luck.
As @apennebaker commented. The issue ended up being a bluetooth keyboard in a backpack.
Ah, "the old" backpack and keyboard problem.
Obviously not everything is better with bluetooth.
Please check your bluetooth and make sure that is not the cause of your problems when troubleshooting keyboard issues.
Try using javascript executor
WebElement yourelement= driver.findElement(By.id("btn"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", yourelement);
I had the same issue with Safari 10+, OSX El Capitan and Selenium 3.0.1
Another alternative may be to send a RETURN key implemented in Python:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Safari()
driver.get('http://localhost:8000')
element = driver.find_element_by_id("submit")
element.send_keys(Keys.RETURN)
The issue is completely solved. The point is element of input[type=file] must not be display: none. Look at sample below:
function click(el) {
// Simulate click on the element.
var evt = document.createEvent('Event');
evt.initEvent('click', true, true);
el.dispatchEvent(evt);
}
document.querySelector('#selectFile').addEventListener('click', function(e) {
var fileInput = document.querySelector('#inputFile');
//click(fileInput); // Simulate the click with a custom event.
fileInput.click(); // Or, use the native click() of the file input.
}, false);
<input id="inputFile" type="file" name="file" style="visibility:hidden; width:0; height:0">
<button id="selectFile">Select</button>
Trigger the click event on the DOM element rather than the jQuery object. That should work in all browsers.
$('#ajxAttachFiles')[0].click();
Or:
document.getElementById('ajxAttachFiles').dispatchEvent( new Event('click') );
//for IE < 9 use microsoft's document.createEventObject
var elem=$('<input id="ajxAttachFiles" name="fileUpload" type="file" style="display: none;"/>');
if($("#ajxAttachFiles").length==0){
elem.prependTo(".ChProgress");
}
$("#ajxAttachFiles").on('click',function() {
alert( 'click triggered' );
});
$("#ajxAttachFiles")[0].click();
//an alternative:
var event = new Event('click');
document.getElementById('ajxAttachFiles').dispatchEvent(event);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ChProgress">Will be added here</div>
I have a MacBook Pro (m1) and quite often, but not all the time, when I click the trackpad (or click the mouse if I have a Bluetooth mouse connected) the click doesn’t register.
It happens enough to be annoying but not every time.
Has anyone else experienced this or have any idea how I can trouble shot.
It does not happen in any other application.
Speculating here, but will confirm later from a Mac. This has been confirmed to be working on a Mac.
Win ctrl+click or a Mac command+click gets picked up by a "normal" click listener, just like a click with any other modifier key (alt+click, shift+click etc).
This is particularly confusing since a ctrl+click on a Mac gets interpreted as a right-click on OS level. Command-click, on the other hand, is not interpreted as a middle-click but rather is a browser preference.
Assuming that you do not have in-site functionality that specifically relies on modified clicks, it would be appropriate to exclude such events from click listeners, and instead allow for them to bubble up to be natively handled by the browser. Given the experience of someone in the similar situation, you should be able to add the following to click handlers (likely a delegate on library level as pointed out by Brilliand):
if (e.metaKey || e.ctrlKey) return;
When added at the beginning of the handler with e referring to a current click event, this should circumvent any following e.preventDefault();
Update:
It actually works! In this rather minimalistic fiddle, I am able to recognize when command-clicked or control-clicked, so as to avoid executing the rest of the click handler which includes ajax-fetching the content and e.preventDefault();. This allows for a command-click to be handled "as intended" on a Mac, i.e. opening the link in a new tab.
With this finding in mind, these lines should now read
if (e.isDefaultPrevented() || e.metaKey || e.ctrlKey) {
return;
}
There is some interesting insight here: https://groups.google.com/forum/#!msg/mozilla.dev.usability/H1qLTur4EFc/gXH007CAPk8J
Apparently the JS you are using can preventDefault() the cmd+click while the middle-click is unaffected. Consult the docs of your JS/Site framework.
I came across this solution add role="button" on <span> and click event start working for IOS device:
<span class="menuOpen" role="button">Menu</span>
It can also be fixed if we replace <span> with <button>
$('.menuOpen').on('click', function() {
console.log('Show Menu');
$('.menuBar').toggleClass('d-none');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<span class="menuOpen" role="button">Menu</span>
<ul class="d-none menuBar">
<li>Action 1</li>
<li>Action 2</li>
<li>Action 3</li>
<li>Action 4</li>
</ul>
References:
Safari HTML Reference
ARIA: button role
Be aware it could be also the accessibility of the JavaScript code. I searched for a solution fixing this bug. But in my case it was a external JavaScript file outside of the html page, which caused the problem. Safari on iOS didn´t seem to reach this external file. Firefox (on iOS) e.g. did open the external JavaScript file, so the event listener worked for Firefox.
Just have put the JavaScript code inside the page and it worked for all mobile device browsers.
This is a repeatable bug for me on my M1 MacBook Pro 14" using Monterrey. Whenever I try to use Command + Click, say to open a link new tab, the first click does nothing. The second click does nothing. Only on the third click does something happen.
Edit: this happens specifically with tap to click. Personally, I always use tap to click, which seems like the more modern way to use a computer given that it resembles the way we interact with smartphones and tablets. But I realize this isn't the default so many people may not be noticing this bug. But it's infuriating. Imagine trying to tap on something on your iPhone in your first two tabs don't work. Or for everything on your computer to require three clicks to work.
Also, I've realized that this is not just restricted to Command + Click, but also Shift + Click and even just plain clicking on things in some instances (again, replace the word "click" with "tap," since that's how I have my trackpad set up).