Double click button Internet Explorer Excel VBA - excel

I am trying to simulate double clicking on an object in internet explorer.
Here is the HTML code:
<tr class="selected lead" style="height: 19px;">
<td class="sort-column" style="width: 1200px; line-height: 17px; text-indent: 19px;">
<img class="bi-tree-view-expand-icon" alt="" src="/resource/image/bid/triangle_collapsed_16.png">
<img class="icon" alt="" src=" /resource/image/bid/folder_closed_16.png">
My Content</td>
<td class="horizontal-filler" style="width: 100px;"> </td></tr>
And the VBA code (which is currently working):
For Each Btn In IE.document.getElementsByClassName("sort-column")
If Btn.innerText = "My Content" Then
Btn.Click
Exit For
End If
Next Btn
I can see the code pressing my button, but what I need is a double click of the button. Any help is greatly appreciated. Thanks!

I spent some time on this and couldn't find a universal answer. It seems any particular method that fires synthetic events may not work depending on a browser's preferred method, control inheritance, and other factors.
Assuming the event is supported, initialized, and has a listener then one of these may work for you.
If your using Chrome, Firefox, or IE 9 and below
Btn.FireEvents("ondblclick")
Except IE 8 which reportedly wants focus on the object
Btn.Focus
Btn.FireEvents("ondblclick")
And if you're on IE 10+ and above then you'll be more successful with:
Btn.dispatchEvent("ondblclick")
I'll be back after building a project to try these out. In the meantime I hope this points you in a helpful direction.

Related

Instead of left click on a link I find I must right click. Why? Is this a new feature or a bit of code that went wrong?

I am facing an issue with slider button link, when I right-click on button it's working fine but not on left-click. I have tried many things, yet do not find any solution.
here is button code:
<a class="wow bounceInUp" data-wow-offset="10" href="https://www.google.com" style="visibility: visible; animation-name: bounceInUp;">Shop Now</a>
I put your button code into a codepen. It does seem to work for me. make sure to start and end your button with <a> </a>
<a class="wow bounceInUp" data-wow-offset="10" href="https://www.google.com" style="visibility: visible; animation-name: bounceInUp;">Shop Now</a>
https://codepen.io/Leeroy-J/pen/podVRvy

Python 3 Selenium - select dynamically generated iframe without a name

(Working with Python 3 and Selenium. Trying to interact with Buffer.com's alert window after pressing "Shuffle" link.)
After pressing a button on the main browser frame, an alert pops up with two buttons. I want to press one of them.
I am trying to change the focus to this iframe that contains the alert, but I can't see it to have a name. Here's the code of said alert iframe:
<iframe src="https://js.stripe.com/v2/m/outer.html#referrer=https%3A%2F%2Fbuffer.com%2Fsignin&title=Buffer&url=https%3A%2F%2Fbuffer.com%2Fapp%2Fprofile%2F55e5cd556321154607cc5244%2Fbuffer%2Fqueue%2Flist&muid=c7aa769e-c41c-4e86-b75f-99771764f6a5&sid=26221bdc-c091-42c2-8965-8ea3e84267e2&preview=false&" frameborder="0" allowtransparency="true" scrolling="no" tabindex="-1" aria-hidden="true" style="width: 1px !important; height: 1px !important; position: fixed !important; visibility: hidden !important; pointer-events: none !important;"></iframe>
The element CONTAINING this iframe, in turn, has a name, but it is dynamically generated. The code of the upper level iframe containing the iframe I want is:
<iframe name="stripeXDM_default441361_provider" id="stripeXDM_default441361_provider" aria-hidden="true" src="https://js.stripe.com/v2/channel.html?stripe_xdm_e=https%3A%2F%2Fbuffer.com&stripe_xdm_c=default441361&stripe_xdm_p=1#__stripe_transport__" frameborder="0" style="position: absolute; top: -2000px; left: 0px;"></iframe>
The "stripeXDM_default441361_provider" is dynamic and changes every time the alert pops up.
I have tried switch_to.frame but could not get it right.
I also tried to select the dynamically-generated iframe with "Xpath containing" but did not work either.
Any suggestions on how I can select this iframe with no name?
To select the iframe, you could use the xpath. For example, if we consider this html:
<!DOCTYPE html>
<html>
<body>
<span id="n2">
<span id="n6">
<a class="cn" name= "A1" >One</a>
</span>
<span id="n7">
<a class="cn" name= "A2" >Two</a>
</span>
<span id="n8">
<a class="cn" name= "A3" >Three</a>
</span>
</span>
</body>
</html>
You can do this:
driver.find_element_by_xpath(("//span[#id='n2']/span[#id='n6']/a[#name='A1' and text()='One']"))
to identify the element with name 'A1' and text 'One'.
But also:
driver.find_element_by_xpath(("//span/span[1]/a[#name='A1' and text()='One']"))
So, in your case you can find the "external" iframe element and after the "internal" one (I assumed there aren't other iframe). Something like this:
//iframe/iframe
After you select the iframe you have to switch to it.
It turns out I was overcomplicating things. I did not need to change focus or anything else.
I just assume that it was all html and I tried to select the element directly with xpath, like so:
#do something
#press shuffle button
#once the button appears in the iframe, blurring everything else, use this line:
button = browser.find_element_by_xpath('//*[#id="modal-buttons"]/a[2]')
button.click()
That's what I did and worked perfectly.

SharePoint view access control

I have the following requirement to fulfill:
I have a view group by "Project" column. Current logged in user need to expand only a project that he/she belongs to (I have a way to get the user's project). The grouped projects have the following forms:
<td nowrap="" class="ms-gb" colspan="100"><img width="0" height="1" alt="" src="/_layouts/images/blank.gif"><a onclick="javascript:ExpCollGroup('1-2_','img_1-2_');return false;" href="javascript:"><img border="0" alt="Expand/Collapse" src="/_layouts/images/plus.gif" id="img_1-2_"></a> <a onclick="javascript:ExpCollGroup('1-2_','img_1-2_');return false;" href="javascript:">Project</a> : Project1 <span style="font-weight: lighter">‎(2)</span></td>
<td nowrap="" class="ms-gb" colspan="100"><img width="0" height="1" alt="" src="/_layouts/images/blank.gif"><a onclick="javascript:ExpCollGroup('1-3_','img_1-3_');return false;" href="javascript:"><img border="0" alt="Expand/Collapse" src="/_layouts/images/plus.gif" id="img_1-3_"></a> <a onclick="javascript:ExpCollGroup('1-3_','img_1-3_');return false;" href="javascript:">Project</a> : Project2 <span style="font-weight: lighter">‎(1)</span></td>
Tried the following but disables all project links:
$('td:contains("Project1") td.ms-gb a').removeAttr("onclick").click(function() { return false; });
Also when a user clicks on project that he/she don't have access to, I need to throw out a message "you do not have access to this project...".
All helps are greatly appreciated! Thanks!
to disable the specified project group linke, use this (project1 for ex.):
$("td:contains('Project1')>a").removeAttr("onclick");
I haven't found out how to change items links' behavior under a certen group. But, even if we can do that, we still can't prevend unauthorized users to access the project items through url directly. The best solution is to stop those items permission inherit and give access permisson only to those people who supposed to read or write the items.

SharePoint 2010 WebPart Personalize Layout

I have a homepage on an Intranet. It has at 15+ webparts (news, weather, etc.) I want to allow the users to customize the page by moving the webparts around or deleting them. At present I don't let them see the ribbon at the top so they don't have access to the "Edit page" button. I have pulled it out from the Ribbon
<a unselectable="on" href="javascript:;" onclick="return false;" class="ms-cui-ctl-large" aria-describedby="Ribbon.WebPartPage.Edit.Edit.Menu.Actions.Edit_ToolTip" mscui:controltype="Button" role="button" style="height: auto;" id="Ribbon.WebPartPage.Edit.Edit-SelectedItem">
<span unselectable="on" class="ms-cui-ctl-largeIconContainer">
<span unselectable="on" class=" ms-cui-img-32by32 ms-cui-img-cont-float">
<img unselectable="on" alt="" src="/_layouts/1033/images/formatmap32x32.png" style="top: -160px; left: -96px;">
</span>
</span>
<span unselectable="on" class="ms-cui-ctl-largelabel" style="height: auto;">Edit<span unselectable="on">
</span>Page</span>
</a>
Unfortunately it is not working. Any thoughts?
I will be doing the same with the "Stop Editing" button as well.
According to this post: http://artykul8.com/2011/03/useful-sharepoint-shortcuts/
the trick is to use the MSOLayout_ToggleLayoutMode(); javascript function.
According to a comment in that same page, in SP2010, that javascript function is only available when you already have a web part in the page. The behavior I observed differs from this one, given that, to me, this function only worked when the page was in edit mode already (and it worked even when the page had no web part added).
I was able to find the javascript file where that function is defined, which is the ie55up.js. You can load it in your masterpage by doing:
<SharePoint:ScriptLink language="javascript" name="ie55up.js" OnDemand="false" runat="server" />
For information about how to build a web control that uses that javascript function, see here: http://www.codeproject.com/KB/sharepoint/SwitchWPMode.aspx
Hope this helps
I finally found the answer to this question. It was very simple after the JS call was determined. I believe this should be for a webpart only page.
To put the page in edit mode for Personalization via a Javascript call:
ChangeLayoutMode(true); // how simple is that??
To stop the editing of the page via a Javascript call:
MSOLayout_ToggleLayoutMode(); // same as given in the other post
The "Stop" edit mode I believe is the same for all pages no matter if it's a personalized page, all webparts page, etc.

2 iframes with the same display even if the src are different

I am using this code:
<div class="infobox-pair">
<div class="ibp-left">
<iframe width="105" height="350" frameborder="0" scrolling="no" style="width: 311px; height: 105px;" marginwidth="0" marginheight="0" name="infobox_flight" id="ibp-left-iframe" src="http://mywebpage.com/paris"></iframe>
</div>
<div class="ibp-right">
<iframe width="105" height="350" frameborder="0" scrolling="no" style="width: 311px; height: 105px;" marginwidth="0" marginheight="0" name="infobox_package" id="ibp-right-iframe" src="http://mywebpage.com/lisbonne"></iframe>
</div>
That is displaying into the same div two different iframes. When I display the page whatever the browser it happens that I can get the same content for both the iframes even if looking at the source code the iframe are still different (based on their src and id).
It doesn't happen 100% of the time, I have to refresh sometimes several times to see it.
Do you have any clue ?
Thanks in advance
One thing to keep in mind, when you refresh in IE and some other browsers, the browser will retain the "current" src="" value for iframe, so if you navigated around a bit in the iframes, then hit F5, the current last navigated path for each iframe is still in the iframes. Is it possible you navigated to the same page somehow?
The only reliable way to get the iframes to "Reset" back to their initial src values on a refresh(f5) is to use javascript to set their src as a part of the page load event. I recommend setting the initial src in markup to just "about:blank" and alwyas programatically change it.
This has been a long time answered but have some additional info that might help web developers.
If you have loaded iFrame 1 in the browser before, then the newly added iFrame 2 will show the same content, even after refreshing multiple times. Try hitting Ctrl + F5, or clearing your temp files in browser, this can reset the iFrame src to it's correct value.

Resources