Link to home
Start Free TrialLog in
Avatar of thenelson
thenelson

asked on

click a button and select a drop down item in a webpage

I call up the following webpage in a frame that I do not have scripting access:
https://docmein.com/app/page/12801944916418372

I enclose the above page in the frame:
https://www.barnwellmd.com/patients/docmeinframe.html.

When I open the docmein.com page, I would like to automatically click the button:
<div class="docmein_button" id="newAppointment_12801944916418372">SCHEDULE NOW</div>

Then when the "Request New Appointment" popup opens (click on "Schedule Now" to see it) I would like to automatically select "1ST appointment for NEW PATIENTS" in the service drop down box.

Is this possible? If so, how?

TIA
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

I'm not well versed in php as I am in asp.   In a case like this I would bring the html content directly on to the page.  In php I think you can do this http://php.net/manual/en/domdocument.loadhtmlfile.php 

<?php
$doc = new DOMDocument();
$doc->loadHTMLFile("filename.html");
echo $doc->saveHTML();
?>

Open in new window

From there, you can use jquery in your page to do what you need.
I would like to automatically click the button:
What does that mean, exactly?
Avatar of thenelson
thenelson

ASKER

padas,
Will loading the html content directly on to the page load it and the links so I and the user can work with the page and the popups?

Ray_Paseur,

Programmaticly click the "Schedule Now" button so when the patient opens the https://docmein.com/app/page/12801944916418372 webpage (via a link on my website), it opens with the "Request New Appointment" popup opened for him with "1ST appointment for NEW PATIENTS" in the service drop down box already selected.

Even though I have an alert box explaining what the patient should do, they frequently get it wrong so I would like to have those choices preselected for them.
You have the following options

1) install a browser script like greasemonkey and create a userscript
2) use a proxy on barwellmd that reads the other site on the server and pretends to click the button (submits the form)
3) run the sites in an HTA (html application) where your frame can click the button since it does not have security restrictions

You do NOT have the possibility in a normal browser due to cross origin security
mplungjan,

I believe you understand the problem.
1) install a browser script is not workable because I do not have (or want) control over the user's browser.

Options 2 and 3 may work except I do not know how to do these. I do have some html, javascript and php experience and I have created VBA applications through IE that automate a web browsing session but I do not know how to automate pushing a button or watching for a drop down box and selecting its entry from the server side using html, javascript and/or php. So I would appreciate you showing me how to get started on that or pointing me to a web reference that would help me do that.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Fantastic! I didn't expect you to write something that I could just copy and use but you did!!

One issue,
Since docmein uses "EXISTING patient followup visit ONLY" (selectedIndex=1) as the default for the popup window, it finds the first available one hour appointment. If a user manually selects "1ST appointment for NEW PATIENTS", the window then shows "No available time slots found for the date specified. Please select a different date." This does not happen with "sels[sel].selectedIndex=0;". How do we activate the drop down box after selecting index 0? I tried adding "sels[sel].click();" after "sels[sel].selectedIndex=0;" but that didn't do it. I also tried changing "sels[sel].selectedIndex=0;" to "sels[sel].options[0].selected = true;" but still no luck in activating the selection.

Then two other questions for my understanding:
Couldn't you just search for "if (divs[div].id.indexOf("newAppointment")!=-1)"? I see that is needed since there are two buttons with className=="docmein_button" but why did you search for "if (divs[div].className=="docmein_button")" first?

How did you find the className=="GNAI25MLJ"? I viewed the source code for the webpage "https://docmein.com/app/page/12801944916418372" but did not see the source code for the popup window.

Thanks!!
Hi,

1) yes remove the outer if, it is a leftover from trying to use querySelectorAll to get the divs with the correct class name but that does not work in hta for some yet unknown reason.

2) I cannot test until Monday since I only have macs at home.

3) I found the className using inspect element in chrome after clicking the picker button

4) try
sels[sel].selectedIndex=0;
sels[sel].onchange();
sels[sel].onchange();
causes the error: "Unable to get property 'return value' of undefined or null reference"
With your suggestion of
sels[sel].onchange();
I was able to find the solution:
sels[sel].fireEvent("onchange");

Thanks a lot!!
You are welcome.
Fell free to visit my site in my profile
mplungjan,

Ran into a problem with .hta. When I uploaded it to my server (www.barnwellmd.com/twilio/click.hta), IE and FF just shows the code and Chrome downloads the file.

So this won't work. Is there a way to fix this problem so the hta just runs in the browser? Should I open a new question for this?

Or perhaps we need to look at your suggestion: "2) use a proxy on barwellmd that reads the other site on the server and pretends to click the button (submits the form)"  I created a new question to handle that: https://www.experts-exchange.com/questions/28227768/click-a-button-and-select-a-drop-down-item-in-a-webpage-2.html
An HTA runs your code because it runs from the harddisk and therefore has lowered security. That is how HTAs work.

The only other way if you want this to be available in a browser without downloading is if you use a proxy