Skip to content

[πŸ› Bug]: When I execute driver.find_element(By.ID,'simpleAlert').click() , Alert Window closes in an instant without my permission.Β #15418

@redblueko

Description

@redblueko

What happened?

When I execute driver.find_element(By.ID,'simpleAlert').click() , Alert Window closes in an instant without my permission.

import time
from selenium import webdriver
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
import os
import sys
from selenium.webdriver.common.alert import Alert
import datetime as dt
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException

options = webdriver.ChromeOptions()
options.add_argument("Accept-Language=" + "ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7")
options.add_argument("User-Agent=" + "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36")
options.add_argument("--disable-blink-features=AutomationControlled")
# options.add_argument("--headless=new")

driver_path = ChromeDriverManager().install()
correct_driver_path = os.path.join(os.path.dirname(driver_path), "chromedriver.exe")
driver = webdriver.Chrome(service=ChromeService(executable_path=correct_driver_path), options=options)
# driver.maximize_window()
driver.set_page_load_timeout(5)
driver.implicitly_wait(5)

driver.get('file:///E:/py/aaa.html')
time.sleep(2)

inputElement = driver.find_element(By.ID,'simpleAlert')
inputElement.click()
time.sleep(2)

alert = driver.switch_to.alert
alert.accept()
time.sleep(2)
<!DOCTYPE html>
<html>
<script>
	function simpleAlert() {
		alert("Hello! I am a simple alert box!");
	}

	function confirmAlert() {
		var txt;
		var r = confirm("Press a button!\nEither OK or Cancel.\nThe button you pressed will be displayed in the result window.");
		if (r == true) {
			txt = "You pressed OK!";
		} else {
			txt = "You pressed Cancel!";
		}
		document.getElementById("confirmMemo").innerHTML = txt;
	}

	function promptAlert() {
		var person = prompt("Please enter your name", "Harry Potter");
		if (person != null) {
			document.getElementById("inputMemo").innerHTML = "Hello " + person + "! How are you today?";
		}
	}
</script>

<body>

<p>Click the button to display a simple alert box.</p>
<button onclick="simpleAlert()" id="simpleAlert">Try it</button>

<p>Click the button to demonstrate line-breaks in a confirm box.</p>
<button onclick="confirmAlert()" id="confirmAlert">Try it</button>
<p id="confirmMemo"></p>

<p>Click the button to demonstrate the prompt box.</p>
<button onclick="promptAlert()" id="promptAlert">Try it</button>
<p id="inputMemo"></p>

</body>
</html>

How can we reproduce the issue?

See the code above

Relevant log output

See the code above

Operating System

Windows 10

Selenium version

Python selenium 4.27.1

What are the browser(s) and version(s) where you see this issue?

Chrome 134.0.6998.37

What are the browser driver(s) and version(s) where you see this issue?

Chrome Driver 134.0.6998.88

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions