воскресенье, 3 декабря 2017 г.

AQA: Selenium: Javascript collection of tricks

Collection of knowledge about selenium + js 



Console на полную: console, log, info, warn, assert, trace (link1)
Clipboard copy and paste (link1)

Insert data in textarea:
- how to send a page source to a text area (link question, link with java examples). Used code:
String page=driver.getPageSource();
WebElement e=driver.findElement(By.xpath("textarea xpath");
e.sendKeys(page);
-  Using sendKeys( ) command for entering multiple lines of text into a Text Area field (link). Used code:
const text2 = "My super long text \n string to be typed into \n textarea element";
\b - backspace
\t -  tab
\n - newline
\f -  form feed
\r - carriage return
\" - double quote
\' -  single quote
\\ - backslash
- Using clipboard. (link)
Clipboard.SetText(trgt);
myTextArea.SendKeys(OpenQA.Selenium.Keys.Control + "v");
- Learn how to upload a file using Selenium Webdriver with Sauce Labs’ guide.(link1, link2)
- C помощью Selenium Webdriver ввести текст в frame редакторa tinymce (link1):
driver.switchTo().frame("news_globalize_translations_attributes_ru_content_ifr");
driver.findElement(By.id("tinymce")).sendKeys("Text");
driver.switchTo().defaultContent();

JavaScriptExecutor in Selenium WebDriver With Examples (original link)

JavaScriptExecutor in Selenium WebDriver:
In general, we do click on an element using click() method in Selenium.
For example:
Sometimes web controls don’t react well against selenium commands and we may face issues with the above statement (click()). To overcome such kind of situation, we use JavaScriptExecutor interface.
It provides mechanism to execute Javascript through Selenium driver. It provides “executescript” & “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window.
There is no need to write separate script to execute JavaScript within the browser using Selenium WebDriver script. Just use predefined interface named ‘Java Script Executor’. We need to import the below package in the script.
Package:
Syntax:
Script – The JavaScript to execute
Arguments –
The arguments to the script(Optional). May be empty.
Returns –
One of Boolean, Long, String, List, WebElement, or null.
Let’s see some scenarios we could handle using this Interface:
  • To type Text in Selenium WebDriver without using sendKeys() method
  • To click a Button in Selenium WebDriver using JavaScript
  • To handle Checkbox
  • To generate Alert Pop window in selenium
  • To refresh browser window using Javascript
  • To get innertext of the entire webpage in Selenium
  • To get the Title of our webpage
  • To get the domain
  • To get the URL of a webpage
  • To perform Scroll on application using  Selenium
See Also: How To Scroll Web Page Down Or UP Using Selenium WebDriver
  • To click on a SubMenu which is only visible on mouse hover on Menu
  • To navigate to different page using Javascript
  • To find hidden element in selenium using JavaScriptExecutor
Below program will guide you to handle some of the scenarios we do use in while writing scripts.
If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

 


Комментариев нет:

Отправить комментарий

SEO: Эксперимент: как Яндекс и Google учитывают ключевые слова в URL

Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Эксперимент: как Яндекс и Google учитывают ключевые слова в URL Дата пу...