Click button and get text with CeFSharp - javascript

I'm creating a program in vb.net to go to https://www.royalmail.com/track-your-item#/ and:
Enter some text in the Reference Number box
Click the button 'Track your delivery'
Grab the text from the page so I can search for the delivery date
I've had to switch to using CeFSharp, as the microsoft browser doesn't want to load the page, so this is my first time with it.
This is what I have so far (CWB1 is the name of the browser object):
CWB1.LoadUrl("https://www.royalmail.com/track-your-item#")
CWB1.LoadUrl("javascript:void( document.getElementById( 'barcode-input' ).value='12345678' )")
Dim script = "var pagebutton = document.getElementById('submit');
pagebutton.click();"
CWB1.ExecuteScriptAsyncWhenPageLoaded(script)
The page loads, the text '12345678' is entered in the search box, but running the script to press the button does nothing.
I can't figure out how to press the button. I thought it must be the wrong id, but inspecting the web page seems to give button id="submit" so this should work? I've tried a few variations but nothing seems to move me forwards.
I also then need to grab the text from the page - not sure how to so this either?
Thanks for any help!

OK, I've found that the button press only works if you enter the text in the field via sendkey event. So the button press code was working after all - I guess the site's security is trying to make sure someone is typing the text in, instead of a robot. Thanks for your help with this amaitland!

Related

Copy to clipboard and send keycode

The function from my Softphone (VoIP Phone on my PC) is, when I copy a phone number in clipboard and then I press "Pause" (German Keyboard), the softphone dials the number. I have created which help from some code examples in internet a copy function, which copied from a field in my database the phone number in the clipboard, when I press a button. It works perfectly. Now I wish to dials the number immediately and therefore it is necessary, the button do not copy the number only, but rather simulated the key press "Pause" after the copy.
Unfortunately my knowledge in PHP is ok, but in JavaScript it is very very bad. And therefore my request is for help me in this case.
Thank you very much in advance
Here is my script:
// in $Mobil01 is the phone number
]
<button class=copy-button id=buttonM01><i class=fa fa-copy style=font-size: 20px;></i></button>
<script>
var telefonM01 = document.getElementById("telefonM01")
var buttonM01 = document.getElementById("buttonM01");
buttonM01.addEventListener("click", function (eventM01) {
eventM01.preventDefault();
telefonM01.select();
document.execCommand("copy");
});
</script>
The select event occurs only when a text is selected (marked) in a text area or a text field. So, for working with this you will have to set the element with the id telefonM01 as some input or textarea element.
An alternate way of copying text is to attach the text with the button to copy.

Changing Text Input from Chrome Bookmark

I am trying to fill out text input's on a site that does not have JQuery. However, I keep getting a null return when trying to use Javascript's getElementById function with a Google Chrome Bookmark.
How to replicate:
Go to W3Schools: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_text_value2
Add this as a bookmark:
javascript:(function(){
console.log(document.getElementById("myText"));
})();
Click on the bookmark and see "null" in the console instead of the text input.
(To get the desired output you can change W3's code to console.log the element instead of changing it's value and then click the W3's "Try it" button)
--
The goal here is to be able to change these text input values by script.
Ex) Change "Mickey" to "Johnny Bravo" through bookmark click
Drag the padlock icon to your bookmarks toolbar, right-click, edit and set the URL to:
javascript:document.getElementById("myText").value = "Johnny Bravo";document.close();
Then click it to change the value of myText. You need to close the document after setting the value or it will write to a new document.
The bookmarklet above won't work in your TryIt editor because the form is in an iFrame named 'iframeResult'. But this works:
javascript: window.frames.iframeResult.document.getElementById("myText").value = "Johnny Bravo";document.close();

Javascript issue- Cannot Submit form after document.getElementById

document.getElementById("hs-search-origin").value = myloc;
I am successfully writing the value in a Text Box
The text box is attached to a searchbox and up on clicking the search button, search is not happening.
I have to edit the textbox, like remove character or add character in the text box, to make it work.
For Ex:
myloc="i love stackoverflow";
document.getElementById("hs-search-origin").value = myloc;
The text box shows the value i.e "i love stackoverflow" but on clicking the button, nothing happens.
I have to either edit the text in the textbox and then click on search to make it work. What is the issue, any guess
You have some code which runs (and does a search) when the user changes the value of the text box.
It doesn't run when you change the value with JavaScript.
You need to call that code explicitly when you want it to fire in response to something else than the user typing.

Formating in Alert Message with addition of image

Is it possible to achieve formatting of text in JS alert message?
<script>
function myFunction() {
alert("1.Enter your name. 2. Enter your mobile no. 3.Do not press back
button.");
}
</script>
I want these 3 messages to appear one below the other. I tried:
<p>1.Enter your name.</p><p> 2. Enter your mobile no.</p><p> 3.Do not
press back button.</p>
Didn't work. Also, wish to add this img src tag after the last message:
<img src="http://forums.nextgames.com/resources/emoji/smiley.png" alt="smily"/>
Thank you.
The alert box is a object, and not related to CSS. To do this style of thing you would need to create an HTML element and mimic the alert() functionality. The jQuery UI Modal box does a lot of the work for you.
try adding "/n" before the lines example "\n2", "\n3"
The browser alert box does not support rendering HTML, however you can use plain-text formatting like \n newline and \t tab.
alert("1.Enter your name.\n2. Enter your mobile no.\n3.Do not press back button.");

Get User Comments from a Prompt Box also on Cancellation

I am building a HTML application (with Javascript, CSS). It is an user-interaction based application. I have a requirement where the user gets a prompt box with option to enter his/ her comments and to either accept (OK) or reject (Cancel) the action. When the user accepts (OK) i can read the user-comments. However, I also want capture the user comments when the Cancel button is pressed.
Most of the examples which I saw (either using custom box or window.prompt) only read the inputs on OK but nothing on cancel. Also as per window.prompt definition it does not read the comments box on cancellation. How can this be achieved?
if (alertInfo.indexOf(checkString) > -1){//check if a string is present in the message
var showPrompt = window.prompt("Please enter your remarks", "");
if(showPrompt != null){
userAccepted(showPrompt);
}
else{
sendRejection();// This is where I also need to read the user comments
}
}
else{
//reload the page
}
You're trying to misuse the feature. Cancel means cancel, not "OK but do something else". That's why you can't do this.
You'll have to find another way, such as rendering your own <form> to obtain the comments.
As #Lightness Races in Orbit said, you simply can't do it with the windows prompt. You have to make a floating div and make it visible instead of the windows prompt.
You can have radio buttons that requires the user to accept or decline, a text box to enter comments and a single OK button to close the dialog ("basically hiding the DIV").
Instead of a floating div, the user was directed to a new page where he / she could enter the inputs and either accept or reject the action. The advantage of having a separate page is that the user does not have to zoom-in / out the page to properly view the contents.
Thanks.

Categories

Resources