Jump to content
Sign in to follow this  
xBizzet

How can I validate this form using Javascript?

Recommended Posts

xBizzet

Hello AutoIt Community!

 

I have no where else to go so I have came here for some hope! Haha.

I am trying to validate this form to I can upload an image to a website. For some reason, every time I dynamically add a value to the URL input box, it does not allow me to upload.

I need some type of work around. Here is my code. I feel like I have tried everything.

// ;: INCLUDES :;

#include <IE.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>

// ;: IE DOCUMENT :;

Local $oIE = _IECreate("https://wordpress.com/post/ENTER YOUR BLOG HERE")
Local $oDoc = _IEDocGetObj($oIE)

Sleep(3000)
$oDoc.querySelector("button.editor-drawer-well__placeholder").click()

Sleep(1000)
$oDoc.querySelector("button.media-library__upload-more").click()

Sleep(1000)
$oDoc.querySelector("div.media-library__header-popover .popover__inner .popover__menu .popover__menu-item").click()

Sleep(2000)
$oDoc.querySelector("form.media-library__upload-url .form-text-input").focus()


Local $oInput = $oDoc.querySelector("form.media-library__upload-url .form-text-input")
_IEFormElementSetValue($oInput, "http://lorempixel.com/400/200")

// I have also tried
// $oInput.value = "http://lorempixel.com/400/200"


$oEvt1 = $oIE.document.createEvent("Event1")
$oEvt1.initEvent("change", True, False)
$oInput.dispatchEvent($oEvt1)

$oEvt2 = $oIE.document.createEvent("Event2")
$oEvt2.initEvent("input", True, False)
$oInput.dispatchEvent($oEvt2)

$oEvt3 = $oIE.document.createEvent("Event3")
$oEvt3.initEvent("keydown", True, False)
$oInput.dispatchEvent($oEvt3)

$oEvt4 = $oIE.document.createEvent("Event4")
$oEvt4.initEvent("keypress", True, False)
$oInput.dispatchEvent($oEvt4)


Sleep(3000)

$oDoc.querySelector("div.media-library__upload-url-button-group .button").focus()
$oDoc.querySelector("div.media-library__upload-url-button-group .button").click()

 

For some reason, the console always outputs this and this

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help http://xhr.spec.whatwg.org/
e.extension is undefined

 

What else could I try? I am lost at this point. Been trying for 3 days...

 

Share this post


Link to post
Share on other sites
mrflibblehat

I imagine e.extension is coming from the js console. the XML error you see is defined in JQuery.  Maybe e.extension is.

If you go to the site... look at the source, anything related to e.extension or just extension in any of the source script files?

in chrome you can also check the network section and js console.


[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

Share this post


Link to post
Share on other sites
Danp2

The site used the ReactJS library, which can be a PITA to automate. I previously wrote some code to deal with this in FF. Unfortunately, this doesn't appear to be working with this version of the library.

The good news is that I found some code here that appears to work when I manually ran it in the console.

var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
nativeInputValueSetter.call(input, 'react 16 value');

var ev2 = new Event('input', { bubbles: true});
input.dispatchEvent(ev2);

This appears to work fine in my testing. Now you just need to implement the solution in Autoit. :sweating:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×