Automate the Onclick screen popup - powershell

Using IE I have automated a site but now after everything, I got stuck with a form which throws a dialogue box "Message from Webpage" Ok or Cancel.
Dialogue Box Image
Brower's HTML inscpect :
<div class="formbuttons">
<input name="Deactivate" class="formsubmit deactivate" id="ButtonDeactivate"
style="width: 160px;" onclick="return confirm('Are you sure you want to
deactivate the feature?');WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(
"ctl00$ContentPlaceBody$ButtonDeactivate","", true, "
", "", false, false))" type="submit" value="Deactivate">
</div>
The methods I have tried :
1. By removing the onclick from html but it didn't help though regular expression is actually removing it
[String] $body = "onclick=.*feature....."
$ie.Document.body.innerHTML -replace "$body", ""
$deactivate=$ie.document.getElementById("ButtonDeactivate")
$deactivate.Click();
2. By adding few statements as mentioned here (Automating IE confirmation prompt with Powershell)
$ie.document.forms | Select -First 1 | % { $_.submit() }
My only motive is to click on the OK popup button.
Thanks for the help in advance.

Try to query the Outer HTML property of the item to get the HTML code. Then all you have to do is replace the "confirm (*)" with "". After that you can set it back into the script and then click it.
$Script = $IE.document.getElementsByTagName("script").item(#----------Whatever Number it is)
$Script.outerHTML = $Script.outerHTML | % {if ($_ -like "return confirm*") {"return true;"} else {$_}}
$autotransbtn.Click()
Reference:
(1) Automating JavaScript confirmation prompt in IE using PowerShell
(2) internet explorer - Automating IE confirmation prompt with Powershell

Related

You cannot call a method on a null-valued expression. clicking button in webpage via powershell

I am trying to click a button within a synology nas webpage environment.
Sadly the $link=$ie.Document.getElementByID('ext-gen258') $linck.click()
doesn't work as the element id constantly changes when you reload the page.
The element im trying to open:
<div class="item-wrap" id="ext-gen1413" role="button" aria-labelledby="controlpanel:leaf_security" cate="tree:node_connection" fn="SYNO.SDS.AdminCenter.Security.Main">
<div class="icon-image syno-app-admin-center-icon-image" style='background-image: url("webman/modules/AdminCenter/images/default/1x/home_icons/security.png?v=25426-s2");'></div>
<div class="text" id="controlpanel:leaf_security">Beveiliging</div>
</div>
I also tried the following code:
$button = $ie.Document.getElementsByTagName("div") |
Where-Object {$_.value -eq "controlpanel:leaf_security"}
$button.click()
But then the code wont resume and get stuck.
What am I doing wrong?
$doc = $ie.document
# commit the button
$commit = $doc.getElementById("controlpanel:leaf_security")
if ($commit) { $commit.click() }
this code works... dont know why tho would love to have a explanation.

Laravel Backpack javascript dynamic change of select option

I am running laravel backpack 3.4 and created a custom select2 fieldtype from the standard one, I am now trying to based on an onchange event change the value selected on another select options but no change is happening
This is the field declararion
<select onchange="updateunit(this, '{{$field['name']}}' )" id="{{$field['name']}}_<% $index %>" data-index="<% $index %>"
ng-model="item.{{ $field['name'] }}"
[ngValue]="value"
#include('crud::inc.field_attributes', ['default_class' => 'form-control select2'])
>
<option value="">-</option>
#if (isset($field['model']))
#foreach ($field['model']::all() as $connected_entity_entry)
<option value="{{ $connected_entity_entry->getKey() }}"
>{{ $connected_entity_entry->{$field['attribute']} }}</option>
#endforeach
#endif
</select>
And this is the way I am trying to modify the select field selected option
function updateunit(object,name){
var fieldname;
fieldname = object.id;
fieldname = fieldname.replace('product_id','order_unit');
/* data:'_token = <?php echo csrf_token() ?>', */
$.ajax({
type:'POST',
url:'/getmsg',
data: {id:object.value},
async: false,
success:function(data) {
alert(fieldname);
alert(data.msg);
document.getElementById(fieldname).value = data.msg;
},
error:function(){alert('Unidade de Compra não está definida')},
});
This is not working, but I have not enough knowledge either on JS neither Angular to understand why this won't bind.
The elements that are created by your field configurations use the jquery select2 plugin to create a fancy select box. It does this by hiding the plain select element then displaying an html structure that builds the fancy dropdown etc in its place.
document.getElementById(fieldname).value = data.msg; will set the value of the hidden select field, but will not update the value shown by the plugin's fancy html dropdown.
To make the value that's display by the plugin change, we have to call .trigger('change') so the select element tells any listening javascript (ie the select2 plugin) that it's internal value has changed and the plugin should now update its display to match. ie, run this:
$('#'+fieldname).val(data.msg).trigger('change')
See more detailed documentation here

How to fix browser in live server using visual studio?

New to coding and using visual studio code for Mac for the first time as I am following a coding tutorial on freecodecamp. I installed VSC and live server and Chrome browser extension, yet I get an error when I go to live server:
// = 0 ? '&' : '?') + '_cacheOverride=' + (new Date().valueOf()); } parent.appendChild(elem); } } var protocol = window.location.protocol === 'http:' ? 'ws://' : 'wss://'; var address = protocol + window.location.host + window.location.pathname + '/ws'; var socket = new WebSocket(address); socket.onmessage = function (msg) { if (msg.data == 'reload') window.location.reload(); else if (msg.data == 'refreshcss') refreshCSS(); }; if (sessionStorage && !sessionStorage.getItem('IsThisFirstTime_Log_From_LiveServer')) { console.log('Live reload enabled.'); sessionStorage.setItem('IsThisFirstTime_Log_From_LiveServer', true); } })(); } else { console.error('Upgrade your browser. This Browser is NOT supported WebSocket for Live-Reloading.'); } // ]]>
I tried on Mozilla, but the extension is not even able to be installed as add on corrupt - https://share.getcloudapp.com/WnuG42w2
Tried without the extension on Firefox and got the same error above as Chrome.
Any help would be appreciated!
Recently, I faced the same problem using Visual Code. It is a 'Live Server' error. Live Server tries to inject some code into the original code as a comment, which leads to this error. Refreshing the live server will make things normal again.
Try to close the tag with a closing tag. For example replace:
<textarea
id="message"
name="message"
cols="30"
rows="10"
/>
with:
<textarea
id="message"
name="message"
cols="30"
rows="10"
></textarea>
This actually worked for me.
Please recheck your codes again. See if there is missing some symbol or tag. In VS Code you understand by the code colors.
I had a similar issue like this. Although, I am new to web development field. The code I was faced problem was:
<section>
<div>
<img src="images/designer.png" alt="web designer>
</div>
<div>
<h1>Big Dream</h1>
<h2>To become a developer</h2>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit</p>
</div>
</section>
You see in the alt="" part in the img tag, I have missed a (") double quotation.

Codeigniter and FancyBox to display image gallery

I am using FancyBox to display image gallery. I want, When page open all images shows as thumb after click any image show this image full screen, slide show etc.
my CI view code as below
<div class="container">
<div class="gallery">
<?php
foreach ($records as $rec){
echo "<a href=".base_url()."upload/images/".$rec["file_name"]." data-fancybox="group">";
echo "<img src=".base_url()."upload/images/thumb/".$rec["file_name"].">";
echo "</a>";
} ?>
CI Module Code below:
public function get_data_gallery($table){
$query = $this->db->get($table);
return $query->result_array();
}
CI controller code as below:
public function gallery(){
$data['records'] = $this->ciweb_model->get_data_gallery('images');
$this->load->view('common/header');
$this->load->view('common/menu');
$this->load->view('gallery',$data);
$this->load->view('common/footer');
}
And my Error is below:
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected 'group' (T_STRING), expecting ',' or ';'
Filename: views/gallery.php
Line Number: 32
Backtrace:
My guess is that the problem is here:
.. data-fancybox="group">";
you have mixed "'s, it should be
.. data-fancybox='group'>";

Find Element using Protractor ( Click on login button)

How do I find element in Protractor to click on a button (login button).... I have entered login name and Password but no luck clicking on my "log in" button. My code does not have model, Repeater , ID or class for the login section to enter the App.
Thanks in advance for the help. Ho do I format the actual code so I can run this using Protratcor?
Following is my code:
<div class="btn-panel">
div>
<div ng-show="loginAsAdmin" hs-gesture="{handler: goToPin}" class="ng-hide">
<i class="icon-back-round"></i>
</div>
!--<div class="brad-all attention" hs-gesture="{handler: clearLogin}">
i class="icon-close-round"></i>
</div>-->
<div class="btn-ok" hs-gesture="{handler: doSubscribe}" localize="(!canSubscribe || loginAsAdmin) ? 'Log In' : 'Subscribe'">Log In</div>
</div>
</div>
<div ng-show="loginAsAdmin" hs-gesture="{handler: goToPin}" class="ng-hide">
<i class="icon-back-round"></i>
</div>
<div class="btn-ok" hs-gesture="{handler: doSubscribe}" localize="(!canSubscribe || loginAsAdmin) ? 'Log In' : 'Subscribe'">Log In</div>
Edit for future users (This command was a workaround rather than a direct solution to his original problem of not finding/clicking button):
You could also try submitting the form by hitting enter (you may want to do this while within the password field) - browser.driver.actions().sendKeys(protractor.Key.ENTER).perform();
Another Edit: This also just occurred to me - there is another option to simulate a click event: browser.driver.actions().mouseDown(loginBtn).mouseUp().perform();
Original Post
You say your code does not have an ID or class, but I see your Login links having the class 'btn-ok'? Maybe I'm misunderstanding but you could try using cssContainingText:
var loginBtn = element(by.cssContainingText('.btn-ok', 'Log In');
loginBtn.click();
That will locate the element with a class of 'btn-ok' with the specified string of 'Log In'
Source: https://angular.github.io/protractor/#/api?view=ProtractorBy.prototype.cssContainingText
#kevin Presuming that
' <div class="btn-ok" hs-gesture="{handler: doSubscribe}" localize="(!canSubscribe || loginAsAdmin) ? 'Log In' : 'Subscribe'">Log In</div>
</div>'
is the tag that holds the your login button and also only clicking is what you need. following might work for you:
element(by.xpath("//div[contains(#class,'btn-ok') and contains(text(),'Log In')]")).click();
You can select it by className using element(by.className('btn-ok')) or element(by.css('.btn-ok')) and then simply throw a .click() on the end and voila:
element(by.css('.btn-ok')).click(); or $('.btn-ok').click()