경고 (Selenium IDE) 내부의 확인 버튼을 클릭합니다.
Selenium 명령을 사용하여 경고 창에서 '확인'버튼을 클릭해야합니다 . 나는 시도 assertAlert
했거나 verifyAlert
그들이 내가 원하는 것을하지 않는다.
'확인'버튼을 클릭 할 수 있습니까? 그렇다면 누군가 Selenium IDE 명령의 예를 제공 할 수 있습니까?
Selenium 2.0b1을 사용해보십시오. 첫 번째 버전과 다른 핵심이 있습니다. 문서 에 따라 팝업 대화 상자를 지원해야 합니다 .
팝업 대화 상자
Selenium 2.0 베타 1부터는 팝업 대화 상자 처리를위한 지원이 내장되어 있습니다. 트리거하고 팝업을 여는 작업을 수행 한 후 다음을 사용하여 경고에 액세스 할 수 있습니다.
자바
Alert alert = driver.switchTo().alert();
루비
driver.switch_to.alert
현재 열려있는 경고 개체를 반환합니다. 이 개체를 사용하면 이제 내용을 수락, 해제, 읽거나 프롬프트에 입력 할 수 있습니다. 이 인터페이스는 경고, 확인, 프롬프트에서 똑같이 잘 작동합니다. 자세한 정보는 JavaDocs를 참조하십시오.
경고 상자에서 "확인"버튼을 클릭하려면 :
driver.switchTo().alert().accept();
이것은 2012 년의 대답입니다. 2009 년의 질문이지만 사람들은 여전히 그것을보고 있고 하나의 정답 (용도 WebDriver
)과 거의 유용한 (하지만 충분하지 않은) 대답이 있습니다.
Selenium RC를 사용 중이고 실제로 경고 대화 상자를 볼 수있는 경우 수행 할 수 없습니다. 셀레늄이 처리 해줄 것입니다. 그러나 Selenium 문서에 명시된 바와 같이 :
Selenium은 페이지 실행을 중지하지 않도록 (window.alert, window.confirm 및 window.prompt를 대체하여) 이러한 대화 상자를 숨기려고합니다. 경고 팝업이 표시되는 경우 페이지로드 프로세스 중에 실행 되었기 때문일 수 있습니다. 일반적으로 페이지를 보호하기에는 너무 이릅니다.
이는 Selenium RC (및 따라서 Selenium IDE)의 알려진 제한 사항이며 Selenium 2 (WebDriver)가 개발 된 이유 중 하나입니다. 당신이 처리하려는 경우 onload
JS 경고를, 당신은 필요 WebDriver를 사용하여 경고 처리를 .
그것은 당신이 사용할 수 말했다 Robot
또는 selenium.keyPressNative()
텍스트를 눌러 채우기 위해 Enter맹목적 대화 상자를 확인합니다. 가장 깨끗한 방법은 아니지만 작동 할 수 있습니다. alert
그러나 메시지 를받을 수 없습니다 .
Robot
모든 유용한 키가 상수에 매핑되어 있으므로 쉽습니다. 를 사용하면 ASCII 코드 와 함께 작동하므로 또는 for 를 누르기 위한 값 keyPressNative()
으로 사용하려고합니다 .10
Enter27
Esc
1 | 경고 팝업 텍스트를 인쇄하고 닫기 -I
Alert alert = driver.switchTo().alert();
System.out.println(closeAlertAndGetItsText());
2 | 경고 팝업 텍스트를 인쇄하고 닫기 -II
Alert alert = driver.switchTo().alert();
System.out.println(alert.getText()); //Print Alert popup
alert.accept(); //Close Alert popup
3 | 경고 팝업 텍스트를 지정하고 닫기
Alert alert = driver.switchTo().alert();
assertEquals("Expected Value", closeAlertAndGetItsText());
셀레늄 IDE를 사용하는 경우 경고 메시지 명령이 실행될 때 브라우저가 작동을 중지하고 자동으로 확인 버튼을 클릭하려면 셀레늄 RC 또는 웹 드라이버를 사용해야하며 아래 명령은 Selenium 용이므로 수동으로 확인 버튼을 클릭해야합니다. IDE
셀레늄 ide 사용 storeeval
명령에서 다른 유형의 상자
storeEval | alert("This is alert box") |
storeEval | prompt("This is prompt box. Please enter the value") | text
storeEval | confirm("this is cofirm box") |
chooseOkOnNextConfirmation
문서를 올바르게 읽으면 기본 동작이 될 수 있지만을 살펴볼 수 있습니다 .
질문은 명확하지 않습니다. 페이지로드에 대한 경고입니까? Selenium을 사용할 때 alert()
확인을 위해 제공된 메시지를 캡처하는 자체 버전으로 대체되기 때문에 경고 대화 상자가 표시되지 않아야 합니다.
Selenium은 alert()
자체 버전으로 테스트중인 창에서 기능을 패치해야하기 때문에 페이지로드를 지원하지 않습니다 .
테스트중인 애플리케이션에서 온로드 경고를 제거 할 수없는 경우 GUI 자동화를 사용하여 생성되는 팝업을 클릭해야합니다 (예 : Windows를 사용하는 경우 AutoIT) .
경고 인터페이스를 사용하여 먼저 switchTo()
경고 한 다음을 사용 accept()
하여 확인을 클릭하거나 사용 dismiss()
을 취소합니다.
Alert alert_box = driver.switchTo().alert();
alert_box.accept();
또는
Alert alert_box = driver.switchTo().alert();
alert_box.dismiss();
assertAlert ought to do the trick. I see in the docs that alerts generated in a page's OnLoad event handler cannot be scripted this way (and have experienced it myself, alas, due to the ASP.NET page lifecycle). Could that be what you're running into?
For selenium, an alert is the one which raised using javascript e.g.
javascript:alert();
There is one basic check to verify whether your alert is actually a javascript alert or just a div-based box for displaying some message. If its a javascript alert, you wont be able to see it on screen while running the selenium script.
If you are able to see it, then you need to get the locator of the ok button of the alert and use selenium.click(locator) to dismiss the alert. Can help you better if you can provide more context:
- IDE or RC?
- HTML code of the alert
- your selenium script.
Vamyip
Use chooseOkOnNextConfirmation() to dismiss the alert and getAlert() to verify that it has been shown (and optionally grab its text for verification).
selenium.chooseOkOnNextConfirmation(); // prepares Selenium to handle next alert
selenium.click(locator);
String alertText = selenium.getAlert(); // verifies that alert was shown
assertEquals("This is a popup window", alertText);
...
This is Pythoncode
Problem with alert boxes (especially sweet-alerts is that they have a delay and Selenium is pretty much too fast)
An Option that worked for me is:
while True:
try:
driver.find_element_by_xpath('//div[@class="sweet-alert showSweetAlert visible"]')
break
except:
wait = WebDriverWait(driver, 1000)
confirm_button = driver.find_element_by_xpath('//button[@class="confirm"]')
confirm_button.click()
The new Selenium IDE (released in 2019) has a much broader API and new documentation.
I believe this is the command you'll want to try:
webdriver choose ok on visible confirmation
Described at:
There are other alert-related API calls; just search that page for alert
참고URL : https://stackoverflow.com/questions/1348937/click-in-ok-button-inside-an-alert-selenium-ide
'IT TIP' 카테고리의 다른 글
선택을 사용하여 쿼리 결과에 행 추가 (0) | 2020.11.21 |
---|---|
Emacs Lisp를 사용하여 파일이 존재하는지 어떻게 확인할 수 있습니까? (0) | 2020.11.21 |
여러 파일 내의 전역 변수 (0) | 2020.11.21 |
오류 메시지의 이유는 무엇입니까? (0) | 2020.11.21 |
Bower 종속성 버전 충돌을 해결하는 방법은 무엇입니까? (0) | 2020.11.21 |