{"id":340679,"date":"2022-11-02T15:01:15","date_gmt":"2022-11-02T15:01:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=340679"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=340679","title":{"rendered":"<span>\u041a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c alert, prompt \u0438 confirm \u0432 Selenium 4<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/96c\/e89\/ab6\/96ce89ab638287e5e6e917c4e05e84ff.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/96c\/e89\/ab6\/96ce89ab638287e5e6e917c4e05e84ff.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d alert, prompt \u0438 confirm \u0432 Selenium.\u00a0<\/p>\n<h3>\u041e \u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0435\u0447\u044c?<\/h3>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/30c\/d02\/a59\/30cd02a59cdd6bb1fde8ba0fde71d8b7.gif\" width=\"810\" height=\"316\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/30c\/d02\/a59\/30cd02a59cdd6bb1fde8ba0fde71d8b7.gif\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <a href=\"https:\/\/the-internet.herokuapp.com\/javascript_alerts\"><u>https:\/\/the-internet.herokuapp.com\/javascript_alerts<\/u><\/a> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0440\u0435\u0445 \u0432\u0438\u0434\u043e\u0432 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043e\u043a\u043e\u043d \u0432 JavaScript: alert, prompt \u0438 confirm. \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043e\u043a\u043d\u0430.\u00a0<\/p>\n<h3>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u0432 Selenium 4<\/h3>\n<pre><code class=\"java\">package test; import java.time.Duration; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.Chormedriver;  public class alert {     public static void main(String[] args){         WebDriverManager.chromedriver().setup();         WebDriver driver = new ChromeDriver();         driver.manage().timeouts().implicitWwait(Duration.ofSeconds(10));         driver.get(\"https:\/\/the-internet.herokuapp.com\/javascript_alerts\");         \/\/this is js alerts                        driver.findElement(By.xpath(\"\/\/button[@onclick='jsAlert()']\")).click();         Alert alerts1 = driver.switchTo().alert();         System.out.println(alert1.getText());         alert1.accept();         if(driver.getPageSource().contains(\"sucessfully clicked an alert\"))         System.out.println(\"sucessfully clicked an alert\");          \/\/this is js confirm                         driver.findElement(By.xpath(\"\/\/button[@onclick='jsConfirm()']\")).click();         Alert alerts2 = driver.switchTo().alert();         System.out.println(alert2.getText());         alerts2.dismiss();         if(driver.getPageSource().contains(\"you clicked: Cancel\"))         System.out.println(\"you clicked: Cancel\");          \/\/js Prompt         driver.findElement(By.xpath(\"\/\/button[@onclick='jsPrompt()']\")).click();         Alert alerts3 = driver.switchTo().alert();         System.out.println(alert3.getText());         alerts2.sendKeys(\"this is selenium 4\");         alert3.accept();         if(driver.getPageSource().contains(\"you entered: this is selenium 4\"))         System.out.println(\"you entered: this is selenium 4\");          driver.close();         driver.quit();     } }<\/code><\/pre>\n<h3>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442<\/h3>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 Chrome<\/p>\n<pre><code class=\"java\">WebDriver driver = new ChromeDriver();<\/code><\/pre>\n<p>\u0418 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 <a href=\"https:\/\/the-internet.herokuapp.com\/javascript_alerts\"><u>https:\/\/the-internet.herokuapp.com\/javascript_alerts<\/u><\/a>.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0430\u0437\u0430 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 alert.<\/p>\n<pre><code class=\"java\">driver.findElement(By.xpath(\"\/\/button[@onclick='jsAlert()']\")).click();<\/code><\/pre>\n<p>\u041a\u043d\u043e\u043f\u043a\u0443 \u0434\u043b\u044f \u0430\u043b\u0435\u0440\u0442\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0442\u044d\u0433\u0443 button \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 onclick. \u041a\u043b\u0438\u043a\u0430\u0435\u043c \u043f\u043e \u043a\u043d\u043e\u043f\u043a\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043d\u0435\u0433\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 <code>driver.switchTo().alert()<\/code>, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0430\u043b\u0435\u0440\u0442\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e alert1.<\/p>\n<pre><code class=\"java\">Alert alert1 = driver.switchTo().alert();<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0430\u043b\u0435\u0440\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>alert1.accept()<\/code>.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043e\u043a\u043e\u043d \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0430\u043b\u0435\u0440\u0442\u0430, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043a\u043d\u043e\u043f\u043a\u0438 &#171;Click for JS Alert&#187; \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 &#171;You successfully clicked an alert&#187; (\u0412\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043a\u043b\u0438\u043a\u043d\u0443\u043b\u0438 \u043d\u0430 \u0430\u043b\u0435\u0440\u0442).\u00a0<\/p>\n<pre><code class=\"java\">if(driver.getPageSource().contains(\"sucessfully clicked an alert\")) \u00a0\u00a0\u00a0\u00a0System.out.println(\"sucessfully clicked an alert\")<\/code><\/pre>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043b\u044f JS Confirm, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043d\u0430\u0436\u043c\u0435\u043c &#171;\u041e\u0442\u043c\u0435\u043d\u0430&#187;, \u0432\u044b\u0437\u0432\u0430\u0432 \u043c\u0435\u0442\u043e\u0434 <code>dismiss()<\/code>.<\/p>\n<pre><code>driver.findElement(By.xpath(\"\/\/button[@onclick='jsConfirm()']\")).click(); Alert alert2 = driver.switchTo().alert(); System.out.println(alert2.getText()); alert2.dismiss();<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 &#171;You clicked: Cancel&#187; (\u0412\u044b \u043d\u0430\u0436\u0430\u043b\u0438: \u041e\u0442\u043c\u0435\u043d\u0430).\u00a0<\/p>\n<pre><code class=\"java\">if(driver.getPageSource().contains(\"you clicked: Cancel\")) \u00a0\u00a0\u00a0\u00a0System.out.println(\"you clicked: Cancel\");<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u043a\u043d\u043e JS Prompt.<\/p>\n<pre><code class=\"java\">driver.findElement(By.xpath(\"\/\/button[@onclick='jsPrompt()']\")).click(); Alert alert3 = driver.switchTo().alert(); System.out.println(alert3.getText());<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 &#171;Click for JS Prompt&#187; \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u043f\u043e\u043b\u0435\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0432\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u043a\u0441\u0442.<\/p>\n<pre><code class=\"java\">alert3.sendKeys(\"this is selenium 4\"); alert3.accept();<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 &#8212; &#171;You entered: this is selenium 4&#187; (\u0412\u044b \u0432\u0432\u0435\u043b\u0438: this is selenium 4)<\/p>\n<pre><code class=\"java\">if(driver.getPageSource().contains(\"you entered: this is selenium 4\")) \u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(\"you entered: this is selenium 4\");<\/code><\/pre>\n<h4>\u0421\u0441\u044b\u043b\u043a\u0438<\/h4>\n<p><a href=\"https:\/\/www.selenium.dev\/documentation\/webdriver\/\"><u>Selenium \/ Documentation \/ WebDriver<\/u><\/a><\/p>\n<hr\/>\n<blockquote>\n<p>\u041d\u0430\u0440\u043e\u0434\u043d\u0430\u044f \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u044c \u0433\u043b\u0430\u0441\u0438\u0442: \u041b\u044e\u0431\u0438\u0448\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e API \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c, \u0443\u043c\u0435\u0439 \u0438 json \u043f\u0430\u0440\u0441\u0438\u0442\u044c! \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c RestAssured, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b \u043d\u0430 API, \u0438 JsonSchemaValidator \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0430 <a href=\"https:\/\/otus.pw\/GRhL\/\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/a><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/696988\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/696988\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d alert, prompt \u0438 confirm \u0432 Selenium.\u00a0<\/p>\n<h3>\u041e \u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0435\u0447\u044c?<\/h3>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 <a href=\"https:\/\/the-internet.herokuapp.com\/javascript_alerts\"><u>https:\/\/the-internet.herokuapp.com\/javascript_alerts<\/u><\/a> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0442\u0440\u0435\u0445 \u0432\u0438\u0434\u043e\u0432 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043e\u043a\u043e\u043d \u0432 JavaScript: alert, prompt \u0438 confirm. \u041f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043e\u043a\u043d\u0430.\u00a0<\/p>\n<h3>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0438\u043c\u0438 \u0432 Selenium 4<\/h3>\n<pre><code class=\"java\">package test; import java.time.Duration; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.Chormedriver;  public class alert {     public static void main(String[] args){         WebDriverManager.chromedriver().setup();         WebDriver driver = new ChromeDriver();         driver.manage().timeouts().implicitWwait(Duration.ofSeconds(10));         driver.get(\"https:\/\/the-internet.herokuapp.com\/javascript_alerts\");         \/\/this is js alerts                        driver.findElement(By.xpath(\"\/\/button[@onclick='jsAlert()']\")).click();         Alert alerts1 = driver.switchTo().alert();         System.out.println(alert1.getText());         alert1.accept();         if(driver.getPageSource().contains(\"sucessfully clicked an alert\"))         System.out.println(\"sucessfully clicked an alert\");          \/\/this is js confirm                         driver.findElement(By.xpath(\"\/\/button[@onclick='jsConfirm()']\")).click();         Alert alerts2 = driver.switchTo().alert();         System.out.println(alert2.getText());         alerts2.dismiss();         if(driver.getPageSource().contains(\"you clicked: Cancel\"))         System.out.println(\"you clicked: Cancel\");          \/\/js Prompt         driver.findElement(By.xpath(\"\/\/button[@onclick='jsPrompt()']\")).click();         Alert alerts3 = driver.switchTo().alert();         System.out.println(alert3.getText());         alerts2.sendKeys(\"this is selenium 4\");         alert3.accept();         if(driver.getPageSource().contains(\"you entered: this is selenium 4\"))         System.out.println(\"you entered: this is selenium 4\");          driver.close();         driver.quit();     } }<\/code><\/pre>\n<h3>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442<\/h3>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 Chrome<\/p>\n<pre><code class=\"java\">WebDriver driver = new ChromeDriver();<\/code><\/pre>\n<p>\u0418 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 <a href=\"https:\/\/the-internet.herokuapp.com\/javascript_alerts\"><u>https:\/\/the-internet.herokuapp.com\/javascript_alerts<\/u><\/a>.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0430\u0436\u0438\u043c\u0430\u0435\u043c \u043a\u043d\u043e\u043f\u043a\u0438 \u043f\u043e\u043a\u0430\u0437\u0430 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 alert.<\/p>\n<pre><code class=\"java\">driver.findElement(By.xpath(\"\/\/button[@onclick='jsAlert()']\")).click();<\/code><\/pre>\n<p>\u041a\u043d\u043e\u043f\u043a\u0443 \u0434\u043b\u044f \u0430\u043b\u0435\u0440\u0442\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0442\u044d\u0433\u0443 button \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 onclick. \u041a\u043b\u0438\u043a\u0430\u0435\u043c \u043f\u043e \u043a\u043d\u043e\u043f\u043a\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043d\u0435\u0433\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0432 <code>driver.switchTo().alert()<\/code>, \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0430\u043b\u0435\u0440\u0442\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e alert1.<\/p>\n<pre><code class=\"java\">Alert alert1 = driver.switchTo().alert();<\/code><\/pre>\n<p>\u0414\u043b\u044f \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0430\u043b\u0435\u0440\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c <code>alert1.accept()<\/code>.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043e\u043a\u043e\u043d \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0430\u043b\u0435\u0440\u0442\u0430, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043a\u043d\u043e\u043f\u043a\u0438 &#171;Click for JS Alert&#187; \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 &#171;You successfully clicked an alert&#187; (\u0412\u044b \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043a\u043b\u0438\u043a\u043d\u0443\u043b\u0438 \u043d\u0430 \u0430\u043b\u0435\u0440\u0442).\u00a0<\/p>\n<pre><code class=\"java\">if(driver.getPageSource().contains(\"sucessfully clicked an alert\")) \u00a0\u00a0\u00a0\u00a0System.out.println(\"sucessfully clicked an alert\")<\/code><\/pre>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u043b\u044f JS Confirm, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043d\u0430\u0436\u043c\u0435\u043c &#171;\u041e\u0442\u043c\u0435\u043d\u0430&#187;, \u0432\u044b\u0437\u0432\u0430\u0432 \u043c\u0435\u0442\u043e\u0434 <code>dismiss()<\/code>.<\/p>\n<pre><code>driver.findElement(By.xpath(\"\/\/button[@onclick='jsConfirm()']\")).click(); Alert alert2 = driver.switchTo().alert(); System.out.println(alert2.getText()); alert2.dismiss();<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 &#171;You clicked: Cancel&#187; (\u0412\u044b \u043d\u0430\u0436\u0430\u043b\u0438: \u041e\u0442\u043c\u0435\u043d\u0430).\u00a0<\/p>\n<pre><code class=\"java\">if(driver.getPageSource().contains(\"you clicked: Cancel\")) \u00a0\u00a0\u00a0\u00a0System.out.println(\"you clicked: Cancel\");<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u043a\u043d\u043e JS Prompt.<\/p>\n<pre><code class=\"java\">driver.findElement(By.xpath(\"\/\/button[@onclick='jsPrompt()']\")).click(); Alert alert3 = driver.switchTo().alert(); System.out.println(alert3.getText());<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043a\u043b\u0438\u043a\u0435 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 &#171;Click for JS Prompt&#187; \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043a\u043d\u043e \u0441 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u043c \u043f\u043e\u043b\u0435\u043c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0432\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u043a\u0441\u0442.<\/p>\n<pre><code class=\"java\">alert3.sendKeys(\"this is selenium 4\"); alert3.accept();<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 &#8212; &#171;You entered: this is selenium 4&#187; (\u0412\u044b \u0432\u0432\u0435\u043b\u0438: this is selenium 4)<\/p>\n<pre><code class=\"java\">if(driver.getPageSource().contains(\"you entered: this is selenium 4\")) \u00a0\u00a0\u00a0\u00a0\u00a0System.out.println(\"you entered: this is selenium 4\");<\/code><\/pre>\n<h4>\u0421\u0441\u044b\u043b\u043a\u0438<\/h4>\n<p><a href=\"https:\/\/www.selenium.dev\/documentation\/webdriver\/\"><u>Selenium \/ Documentation \/ WebDriver<\/u><\/a><\/p>\n<hr\/>\n<blockquote>\n<p>\u041d\u0430\u0440\u043e\u0434\u043d\u0430\u044f \u043c\u0443\u0434\u0440\u043e\u0441\u0442\u044c \u0433\u043b\u0430\u0441\u0438\u0442: \u041b\u044e\u0431\u0438\u0448\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e API \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c, \u0443\u043c\u0435\u0439 \u0438 json \u043f\u0430\u0440\u0441\u0438\u0442\u044c! \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c RestAssured, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0442\u0435\u0441\u0442\u044b \u043d\u0430 API, \u0438 JsonSchemaValidator \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0430 <a href=\"https:\/\/otus.pw\/GRhL\/\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435.<\/a><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/696988\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/696988\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-340679","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340679"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/340679\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}