I have script in python playwright. I'm trying to fill in a prompt field in a dialog but the script just clicks in the button, opens prompt dialog and immediately accepts it without filling out the input field with the prompt_text variable. I tried to handle this https://practice-automation.com/popups/.
Method prompt
def prompt(self, prompt_text) -> None:
self.page.once("dialog", lambda dialog: dialog.accept(prompt_text))
self.popup_locator.prompt_trigger_btn.click()
time.sleep(1)
if prompt_text == "":
expect(self.popup_locator.prompt_result_p).to_be_visible()
expect(self.popup_locator.prompt_result_p).to_have_text("Fine, be that way...")
else:
expect(self.popup_locator.prompt_result_p).to_be_visible()
expect(self.popup_locator.prompt_result_p).to_have_text(f"Nice to meet you, {prompt_text}!")
self.popup_locator.prompt_trigger_btn.click()
self.page.once("dialog", lambda dialog: dialog.dismiss())
expect(self.popup_locator.prompt_result_p).to_have_text("Fine, be that way...")
File with tests:
def test_close(set_up):
popup_obj = Popup_page(set_up)
popup_obj.goto()
popup_obj.prompt("Dupa")
popup_obj.prompt("")
I have a file with locators as well, but the button opening dialog works. It doesn't fill out input field in the prompt.
You did not provide full runnable code, so it is hard to know where is bad.
I write a sample test code below from your code, could you try to reflect into your code? The code has screenshot before and after click button, so you can see how it works.