How can I enable a button on a react app using javascript? - javascript

For a project I am trying to login to my local grocery store and automate some interactions without using services similar to Selenium.
Using chrome dev tools and safari dev tools I have been able to login since the login button is always enabled.
document.getElementById('label-email').value = 'ihaveanemail#email.com';
document.getElementById('label-password').value = 'password';
document.getElementById('btnSignIn').click();
When I navigate to my account settings a button is disabled and wont let me submit.
I have tried removing/ changing the disabled attribute on the button but it only changes the color of the button from light grey to a dark grey. (the button is usually red when enabled). I made a custom event and changed the isTrusted attribute of the request but it doesnt work either.
var labelEmailInput = document.getElementById('label-email')
var clickEvent = document.createEvent('MouseEvents');
clickEvent.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
clickEvent.isTrusted = true;
labelEmailInput.dispatchEvent(clickEvent);
I have searched through the event listeners and tried to manually trigger the events related to the button and its parents. I toggled the events to observe any changes to see if I could complete the process.
The button gets enabled when I click on the inputs and the length requirment is met. When the button is enabled I also see a response in the network tab that sends an image of a green check for a text element to use in its confirmation message that the length requirement is met. I believe they are using some form of client side detection.
This is the button
<button type="button" disabled="" class="btn uca-button btn-secondary core-btn btn-sm">Save</button>
Thanks in advance for any help.

Related

Clicking button doesn't trigger event using selenium(Chrome Only). Nothing happens on click, though element found and clickable

I'm trying to automate a customer journey in our application using selenium java. I have a problem with click() method (Chrome browser only).
Scenario: User adds items to cart, select payment method Google Pay and click on proceed to Payment button. On button click user should see sign in to Google child window.
Problem statement: My script successfully find the element 'proceed to pay' button and verify it is enabled and then click on the button. But it doesn't open up the child window. I tried with selenium click(), JavascriptExcutor click(), Keyboard enter and Mouse actions. But nothing works. Surprisingly If I do a manual click on the proceed to pay button in the same automation session it open up Sign in to google child window.
Same script works in other browsers, able to click and see child window of (Google Payment method)
Selenium: 4.3.0
Chrome: 104.0.5112.48 & 103 102 as well
My Application HTML :
enter image description here
**Code : **
I have tried all the possible options as below. There are no frames
String payMethod = "GooglePay ";
if(clickPayMethodV2(payMethod)) {
clickElement(agreeCheckBox, "Agree Terms Check box");
Assert.assertTrue(isElemenEnbaledClickable(ProceedToSecurePay, 4), "ProceedToSecurePay button is disabled for PayPal");
boolean status = isElemenEnbaledClickable(ProceedToSecurePay, 5);
JavascriptExecutor js = (JavascriptExecutor) driver;
//js.executeScript("arguments[0].scrollIntoView();", element);
//Thread.sleep(1000);
driver.findElement(By.cssSelector("srgc2-secure-payment > form")).click();
ProceedToSecurePay = driver.findElement(By.xpath("//button[contains(.,'Proceed to secure payment')]"));
js.executeScript("arguments[0].focus;", ProceedToSecurePay);
js.executeScript("arguments[0].click();", ProceedToSecurePay);
clickElement(ProceedToSecurePay, "ProceedToSecurePay");
js.executeScript("var ele = arguments[0];ele.addEventListener('click', function() {ele.setAttribute('automationTrack','true');});",ProceedToSecurePay);
ProceedToSecurePay.click();
System.out.println(ProceedToSecurePay.getAttribute("automationTrack"));
//System.out.println(ProceedToSecurePay.getShadowRoot().toString());
click(ProceedToSecurePay, "Proceed To SecurePay button");
clickElementJS(ProceedToSecurePay, "ProceedToSecurePay");
}
else {
logInfoExtent("Failed to click on Payment method: "+payMethod +"in checkout Step 3. PAYMENT");
throw new TestException("Failed to select Payment method: "+payMethod +"in checkout Step 3. PAYMENT");
}
Actions action=new Actions(driver);
action.moveToElement(ProceedToSecurePay).perform();
action.moveToElement(ProceedToSecurePay).click().perform();
ProceedToSecurePay.submit();
ProceedToSecurePay.sendKeys(Keys.ENTER);
enter image description here
Your help on this issue would be greatly appreciated.

Unable to click on a button (tag=>EDL-FILE-UPLOAD) using LeanFt +Java automation script

In a web app that we are testing using LeanFt, there is a type button object with the tag (EDL-FILE-UPLOAD). A dialog to browse the file system and upload a file must pop up when this button is clicked.
This happens when the button is clicked manually.
But when I try the .click() or .doubleClick() methods in my LeanFt automation script, nothing happens.
Now this button has a web element child that displays the label.
So i tried XPathDescriptions for the webElement, and tried the findChildren() function as follows
WebElement[] h = browser.describe(Button.class, xPathDescriptionOfButton).findChildren(WebElement.class, xPathDescofWebElement)
for(int i=0;i<h.length;i++) {
h[i].click();
h[i].hoverTap();
h[i].longPress();
h[i].doubleClick();
h[i].click(MouseButton.LEFT);
h[i].fireEvent(EventInfoFactory.createMouseEventInfo(MouseEventTypes.ON_CLICK));
h[i].fireEvent(EventInfoFactory.createEventInfo("click"));
}
None of the above led to the dialog for uploading files popping up.
Is there any other way to make sure that the button is clicked, and the dialog pops up using Java+LeanFt?
Thank you.
I have been able to solve this issue by using the Robot class to perform mouse click and release actions on the co-ordinates of the button.
Robot r=new Robot();
r.mouseMove(xCoordinate, yCoordinate);
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

Is there any way to Disable (or) Remove the Netsuite Standard Edit Button on the View Mode of the Custom Record

I want to disable (or) Hide the standard "Edit" Button on the View Mode of the Custom Record Type. Instead Of Standard Button i have used custom button to access the edit page of the record to particular users. So i want to disable the standard edit button.
My Code:
Script Version: Suite Script 2.0
Client Script
function pageInit(scriptContext) {
var approved = 3;
var currentRecord = scriptContext.currentRecord;
var status = currentRecord.getValue("custrecord_lst_ch_status");
//Hiding The Standard Edit Button When the Status Field is in Approved State
if (status == approved) {
document.getElementById("edit").disabled = true;
document.getElementsByName("edit")[0].disabled = true;
}
}
ERROR:
I'm unable to get the ID of the "Edit" Button. It is getting the NULL value.
It is Possible to Disable (or) Hide on the view mode of the record using client script (or) User Event Script.
Thanks in advance.
Version: SuiteScript 2.0
USER Event Script Before Load Event:
if (context.type == context.UserEventType.VIEW) {
var form = scriptContext.form ;
form.removeButton({
id :'edit',
});
}
The only time I saw the Edit button dissappear is when the record is locked via workflow.
You can create a simple 1 state workflow to lock the record depending on the user role.When you lock the record edit button automatically disappear for the intended user roles.This would be less intrusive way of removing the edit button.
Maybe this is a little bit of late, but for others who want to know the answer. I used the below code to remove the button.
var form = context.form;
form.removeButton('edit');

Have dialog link go to html login page if javascript is disabled

I am building a site which has javascript in it.
In my site if a user clicks on login or register button a modal popup will be shown.
What I need to know is if the user has disable javascript in his/her browser they should be sent to a normal html signup page (Like in imdb.com) when the user clicks the login link.
Give me some tips on what I should do to get result like that.
I am a newbie so don't be too harsh in your reply.
In short, you set dynamic onclick handler for your button and prevent the default event (in the example below with return false). If JavaScript is disabled, the original event (redirection) will work.
HTML:
<a href="/path/to/normal/sign/up.html" id="login">
JavaScript:
document.getElementById("login").onclick = function() {
// show popup
return false;
};
Have a normal link to the sign up page
Add an event listener to create the modal
Prevent the default behaviour of clicking on the link

showSettings callback in Flex?

I am pretty new to flex, so forgive me if this is an obvious question.
Is there a way to open the Security.showSettings (flash.system.Security) with a callback? or at least to detect if it is currently open or not?
My flex application is used for streaming audio, and is normally controlled by javascript, so I keep it hidden for normal use (via absolute positioning it off the page).
When I need microphone access I need to make the flash settings dialog visible, which works fine, I move it into view and open the dialog.
When the user closes it, I need to move it back off the screen so they don't see an empty flex app sitting there after they change their settings.
thanks :)
If you do something like this, it will work in some situations:
var mic:Microphone = Microphone.getMicrophone();
mic.addEventListener(StatusEvent.STATUS, onMicStatus);
If you are just trying to use the microphone and relying on Flash to pop up the dialog to ask the user for permission, Flash will open a dialog with two buttons, Allow and Deny. When the user clicks one of the buttons the StatusEvent will fire, the dialog will close, and you can move the flex app out of the way.
If you are manually opening the settings panel (via Security.showSettings), you get the panel with Allow and Deny radio buttons, and the event will fire when the user clicks on the radio buttons, not when they close the panel, which is probably of less help to you.
Update: flex 4 solution
So when I moved to the flex 4 and started compiling my mxml with adobe's open source mxmlc compiler, the solution below no longer worked because the alert doesn't lose focus when you're in the settings anymore.
As far as I could tell I had to move to a less elegant solution where the user must click "OK" on the alert box every time they are done with the settings.
Here is the new code:
private function setup_smart_hide():void {
// Call this function whenever you make the flex app visible (or add it
// to a show_flex() function if you have such a thing set up)
alert = Alert.show('Click "OK" to continue.', 'Thanks!', Alert.OK, null, function(e:CloseEvent):void {
// calls the external javascript to hide the flex app
hide_self();
});
}
OLD: (flex 3) Got this working...
private function setup_smart_hide():void {
alert = Alert.show('Thanks');
alert.addEventListener(FocusEvent.FOCUS_IN, function(event:FocusEvent):void {
// javascript to hide the flex app
ExternalInterface.call("SB.flex.hide");
});
alert.addEventListener(FocusEvent.FOCUS_OUT, function(event:FocusEvent):void {
// javascript to show the flex app
ExternalInterface.call("SB.flex.show");
});
alert.setFocus();
}
Which is run first thing in the init() function... the only problem is (like Wesley said), the focusOut event occurs when the flex app itself loses focus as well.

Categories

Resources