added function for sending data with js and double checking that it got input

pull/2/head
Yuriy 2 years ago
parent d11f9ef94c
commit ea4552dde8

@ -16,6 +16,25 @@ JS_TryToExecute(JsToExecute,NumberofAttempts := 1,SleepLength:=1000){
js_SendAndCheckWithQuerySelector(Selector,ValueToCheck:="value",SleepLength:=1000,JSStringText:="TEXT"){
js = document.querySelector("%Selector%").value = "%JSStringText%";
try driver.executeScript(js)
sleep, %SleepLength%
js = return document.querySelector("#title").value;
try, status := driver.executeScript(js)
; DevModeMsgBox(status)
if(Status = "")
return "Failed"
else,
return ""
}
; ValueToCheckOptions = innertext,textContent,InnerHTML,outerHTML,value,href,option value ; ValueToCheckOptions = innertext,textContent,InnerHTML,outerHTML,value,href,option value
js_SendAndCheckWithClassName(ClassName:="",ClassIndexNum:=0,ValueToCheck:="textContent",SleepLength:=1000,JSStringText:="TEXT"){ js_SendAndCheckWithClassName(ClassName:="",ClassIndexNum:=0,ValueToCheck:="textContent",SleepLength:=1000,JSStringText:="TEXT"){
jsSend = document.getElementsByClassName('%ClassName%')[%ClassIndexNum%].value = "%JSStringText%"; jsSend = document.getElementsByClassName('%ClassName%')[%ClassIndexNum%].value = "%JSStringText%";
@ -145,8 +164,8 @@ Selenium_LoopToSendValueByName(ElementName,NumOfLoops:=1,SleepLength:=1000,Strin
Selenium_LoopToSendValueToXpath(Xpath,NumOfLoops:=1,SleepLength:=1000,StringTextContent:=""){ Selenium_LoopToSendValueToXpath(Xpath,NumOfLoops:=1,SleepLength:=1000,StringTextContent:=""){
loop, %NumOfLoops% { loop, %NumOfLoops% {
; ToolTip, Loop attempt: %A_index% ; ToolTip, Loop attempt: %A_index%
try driver.FindElementByXPath(Xpath).sendKeys(StringTextContent) ; Click on "upload image" button try driver.FindElementByXPath(Xpath).sendKeys(StringTextContent) ; Click on "upload image" button
catch e { catch e {
if(A_index = NumOfLoops){ if(A_index = NumOfLoops){
Return "Failed" Return "Failed"
} }
@ -217,128 +236,128 @@ Selenium_LoopToClearXpath(Xpath,NumOfLoops:=1,SleepLength:=1000){
; -------------------------------Javascript------------------------------- ; -------------------------------Javascript-------------------------------
ReturnAndDisplayJSData(jsref){ ReturnAndDisplayJSData(jsref){
; msgbox, here goes ; msgbox, here goes
; https://www.w3schools.com/jsref/dom_obj_all.asp ; https://www.w3schools.com/jsref/dom_obj_all.asp
; -----TEXT CONTENT----- ; -----TEXT CONTENT-----
js = return %jsref%.textContent; js = return %jsref%.textContent;
try status := driver.executeScript(js) try status := driver.executeScript(js)
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3,.TextContent:,%status%
OnMessage(0x44, "")
IfMsgBox Yes,{
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
; -----VALUE----- OnMessage(0x44, "OnMsgBoxJSReturnData")
js = return %jsref%.value; MsgBox 0x3,.TextContent:,%status%
try status := driver.executeScript(js) OnMessage(0x44, "")
IfMsgBox Yes,{
OnMessage(0x44, "OnMsgBoxJSReturnData") } Else IfMsgBox No, {
MsgBox 0x3,.value:,%status% TextForClip = js = %js% `n try, status := driver.executeScript(js)
OnMessage(0x44, "") Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
IfMsgBox Yes,{ ; -----VALUE-----
js = return %jsref%.value;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
; -----INNERTEXT----- OnMessage(0x44, "OnMsgBoxJSReturnData")
js = return %jsref%.innerText; MsgBox 0x3,.value:,%status%
try status := driver.executeScript(js) OnMessage(0x44, "")
IfMsgBox Yes,{
OnMessage(0x44, "OnMsgBoxJSReturnData") } Else IfMsgBox No, {
MsgBox 0x3, .innerText,%status% TextForClip = js = %js% `n try, status := driver.executeScript(js)
OnMessage(0x44, "") Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
IfMsgBox Yes,{ ; -----INNERTEXT-----
js = return %jsref%.innerText;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .innerText,%status%
OnMessage(0x44, "")
; -----OuterText----- IfMsgBox Yes,{
js = return %jsref%.outerText;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerText,%status%
OnMessage(0x44, "")
IfMsgBox Yes,{ ; -----OuterText-----
js = return %jsref%.outerText;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerText,%status%
OnMessage(0x44, "")
;-----innerHTML----- IfMsgBox Yes,{
js = return %jsref%.innerHTML;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .innerHTML,%status%
OnMessage(0x44, "")
IfMsgBox Yes,{ ;-----innerHTML-----
js = return %jsref%.innerHTML;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .innerHTML,%status%
OnMessage(0x44, "")
; -----outerHTML----- IfMsgBox Yes,{
js = return %jsref%.outerHTML;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip = js = %js% `n try, status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerHTML,%status%
OnMessage(0x44, "")
IfMsgBox Yes,{ ; -----outerHTML-----
js = return %jsref%.outerHTML;
try status := driver.executeScript(js)
} Else IfMsgBox No, {
TextForClip =js = %js% `n try,status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMessage(0x44, "OnMsgBoxJSReturnData")
MsgBox 0x3, .outerHTML,%status%
OnMessage(0x44, "")
} ; end of fuctions IfMsgBox Yes,{
} Else IfMsgBox No, {
TextForClip =js = %js% `n try,status := driver.executeScript(js)
Clipboard := TextForClip
} Else IfMsgBox Cancel, {
return
}
OnMsgBoxJSReturnData() {
DetectHiddenWindows, On } ; end of fuctions
Process, Exist
If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
ControlSetText Button1, OK OnMsgBoxJSReturnData() {
ControlSetText Button2, Copy DetectHiddenWindows, On
ControlSetText Button3, Return Process, Exist
} If (WinExist("ahk_class #32770 ahk_pid " . ErrorLevel)) {
} ControlSetText Button1, OK
ControlSetText Button2, Copy
ControlSetText Button3, Return
}
}

Loading…
Cancel
Save