Puppeteer - Click button behind a notification - button

Puppeteer 2.1.0
jest-puppeteer 4.4.0
Win 10 64bit
I have this situation https://i.imgur.com/JbcQAhB.png
I want to click the green button but the notification is in my way.
My code:
selector = "//main/div[1]/div[2]/button[1]"
await page.waitForXPath(selector)
const elementHandle = await page.$x(selector)
await elementHandle[0].click()
This code won't click the button, and I know is the notification, because if before the click() I put a waitFor(5000) and close the notification manually then it works just fine
I also tried in the chrome console directly like this, and it works just fine with the notification in front
$x("//main/div[1]/div[2]/button[1]")[0].click()
Also this kind of code should work for headless mode, so the fact that the notification is "In front" should never be an issue.
Possible questions:
Are you using headed mode? Yes, I have to. I'm testing using chrome extensions.
Using Xpath instead of selectors? Yes, I have no option as well, I have to use xpath
Why no closing the notification? It could work (and actually it does for this particular situation), but that's not the only notification that popUps, more of those show up and messes up with other similar buttons. I need to click the button behind the notification
Thanks!

I found a way, I just changed the await elementHandle[0].click() for await page.evaluate(x=>x.click() , elementHandle[0])
I'll leave the question here, hope somebody find it useful

Related

Unsubscribe Reason Not Working in Mailchimp when using MailChimp.Net Library

I am using mailchimp.net library (https://github.com/brandonseydel/MailChimp.Net) to use mailchimp api. And everything is working fine except that the unsubscribe reason does not work when i update the member.
for example:
Under certain event i am using following code to unsubscribe:
existingMember.Status = Status.Unsubscribed;
existingMember.UnsubscribeReason = "Contact Unsubscribed from contact page" ;
//***Notice the Unsubscribe Reason here, i have different pages which has different unsubscribe reason***
await _mailChimpManager.Members.AddOrUpdateAsync(listUserSubscribed, existingMember)
.ConfigureAwait(false);
Now, Next i created webhook in mailchimp as explained here (https://mailchimp.com/developer/marketing/guides/sync-audience-data-webhooks/#create-a-new-webhook). However the unsubscribe reason is always "manual" and it doesnt shows the note that i entered earlier (i.e. Contact Unsubscribed from contact page) .
Is there anything i am missing? or is there any other way to achieve the same?
Thanks in advance !!!

"slotchange" event doesn't trigger at iOS 11

I need to detect the moment when a slot content rendered into my web component. I use slotchange event to track it. It works fine for all the browsers except iOS 11 (for iOS 13+ works ok). Could someone suggest how to do it properly?
So from the next code, I expect to see "firstUpdated" and "slotchange" messages in the console after the page is rendered. But for iOS 11 I have only "firstUpdated".
firstUpdated() {
console.log("firstUpdated");
const slot = this.shadowRoot.querySelector("slot");
slot.addEventListener("slotchange", () => {
console.log("slotchange");
});
}
Here is a sandbox:
https://codesandbox.io/s/minimal-litelement-vanilla-wy61t?file=/src/index.js
and URL to see the result:
https://wy61t.csb.app/
Older versions of Safari handled slot change events wrong - firing them before the elements were added to the DOM. I think firstUpdated is firing after the slot change has. Try using #slotchange=${... syntax instead, though even if that works it will fire out of order.
If that fails you may have check for the assignedElements manually to work around the Safari bug.

auto fill and submit login form when actual click is required

We are investigation option of replacing JavaFx WebView with JxBrowser and the following code snippet worked fine with WebView:
((HTMLInputElementImpl)document.getElementById("username")).setValueForUser("username");
((HTMLInputElementImpl)document.getElementById("password")).setValueForUser("password");
loginButton.click();
the magic was done by setValueForUser, using standard setValue("") does not work as form submit/action is disabled unless someone actually clicked to the fields.
Unfortunately I did not find correct way to implement the same logic with JxBrowser:
InputElement username = (InputElement) document.findElement(By.id("username"));
username.setValue("username");
username.click();
InputElement password = (InputElement) document.findElement(By.id("password"));
password.setValue("password");
password.click();
loginButton.click(); // or form.submit()
username.click() did not help.
I'm thinking about simulating/sending mouse events to browser view, but it will be messy solution.
So it there setValueForUser alternative in JxBrowser?
Thanks,
-Alex

WebDriver open rich:popupPanel

We are testing an application with Selenium WebDriver. HTMLUnitDriver is our choice (because of non-gui-testing) and sometimes IEDriver for Presentationpurposes. Anyway, i try to perform a click on a button, this one has to open an rich:popuPanel(modal=true) and click a Link on that Panel. With IEDriver that's no problem, but with HTMLUnitDriver the popupPanel doesn't open. I tried to perform these clicks in several ways:
JavascriptExecutor jsdriver = (JavascriptExecutor) driver;
jsdriver.executeScript("$('input[id$=freigabeCmd_id]').focus();");
//below are the other tries
// jsdriver.executeScript("$('input[id$=freigabeCmd_id]').click();");
// jsdriver.executeScript("window.document.getElementById('editorViewForm_id:freigabeCmd_id').click()");
// jsdriver.executeScript("arguments[0].click()", freigabeButton);
// jsdriver.executeScript("arguments[0].fireEvent('onclick');", freigabeButton);
further i tried it the "normal way":
freigabeButton.click();
//below are other ways i found here on stackoverflow
// freigabeButton.sendKeys(Keys.ENTER);
// new Actions(driver).moveToElement(freigabeButton).clickAndHold().release().build().perform();
but nothing brought me to get the popupPanel "visible". Anyone got an idea why?! i'm really stuck right now. If you need more Informations pls let me know.
using: HTMLUnit Version 2.12 and latest SeleniumVersion
It might be that your webapp uses javascript to launch the rich pop-up panel, and you are running HtmlUnitDriver with javascript disabled? It is disabled by default, so you need to explicitly enable it.

WebDriver HtmlUnitDriver NoSuchElementException

I'm using Webdriver to test my web application. When I work with FireFoxDriver or ChromeDriver everything seems to be ok. When I work with HtmlUnitDriver though things start to go wrong.
Here is a sample code:
WebDriver driver = new HtmlUnitDriver();
driver.get("http://localhost:8099/");
WebElement loginButton = driver.findElement(By.xpath("//button[#type='button']"));
loginButton.click();
i'v looked at the driver.getPageSource result, and the source code presented there is very partial.
it doesnt show me all the elements. it is the same a clicking view source on the page.
what i need from the driver is the entire source, like firebug or chrome inspector give me.
any ideas on how i can retrieve it?
my app was written with the GWT.
thanks a million
Have you tried to enable JavaScript for HtmlUnitDriver?
I believe that the HTMLUnitDriver emulates IE by default (link) and there are other questions related to clicking buttons with IE. Have you tried this?
// Press enter on the button
loginButton.sendKeys("\n");
Also, have you tried adding an ID to the element and using that to find the button?

Resources