Notes-5
Notes-5
Browser Commands
Navigation Commands
Window Management Commands
Frame and IFrame Commands
Alert Commands
Element Interaction Commands
Element Action Commands
Wait Commands
Keyboard and Mouse Action Commands (Advanced User Interactions)
Cookies Management Commands
Screen Capture Commands
Session Management Commands
Browser Options and Capabilities Commands
Logs Management Commands
JavaScript Execution Commands
File Upload and Download Commands
Proxy Management Commands
Mobile Web Testing Commands (Specific to Appium)
Remote WebDriver Commands
WebDriver Timeout Commands
Browser Commands
Navigation Commands
55. driver.manage().window().getRect(): Retrieves the position and size of the browser window
as a Rectangle object.
56. driver.manage().window().setRect(new Rectangle(x, y, width, height)): Sets the position and
size of the browser window.
57. driver.switchTo().frame(WebElement): Switches focus to a frame using a WebElement
reference.
58. driver.navigate().to("URL"): Opens a new URL in the browser.
59. driver.navigate().back(): Moves backward in the browser's history.
60. driver.navigate().forward(): Moves forward in the browser's history.
61. driver.navigate().refresh(): Refreshes the current page.
41. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@title,
'frameTitleSubstring')]"))): Switches focus to a frame based on a substring match of the title
attribute using XPath.
42. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='frameId' or
@src='frameSrc']"))): Switches focus to a frame based on either ID or src attribute using
XPath.
43. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='frameId' and
not(@src)]"))): Switches focus to a frame based on ID attribute and without src attribute
using XPath.
44. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='frameClass' and
contains(@src, 'frameSrcSubstring')]"))): Switches focus to a frame based on class and
substring match of the src attribute using XPath.
45. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='frameClass' or
@id='frameId']"))): Switches focus to a frame based on class or ID attribute using XPath.
46. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[not(contains(@src,
'excludedSrcSubstring'))]"))): Switches focus to a frame excluding a substring match of the
src attribute using XPath.
47. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@title,
'titleSubstring') or @id='frameId']"))): Switches focus to a frame based on title substring or
ID attribute using XPath.
48. driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[id|='frameIdPrefix']")))
: Switches focus to a frame based on a hyphen-separated list of ID prefixes using CSS
selector.
49. driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title$='frameTitleSuffix'
]"))): Switches focus to a frame based on an ending match of the title attribute using CSS
selector.
50. driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[class*='frameClassSubs
tring']"))): Switches focus to a frame based on a class name substring match using CSS
selector.
51. driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title*='titleSubstring']")
)): Switches focus to a frame based on a title substring match using CSS selector.
52. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='frameName'][con
tains(@src, 'frameSrcSubstring')]"))): Switches focus to a frame based on name and src
substring match using XPath.
53. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='frameId' and
@title='frameTitle']"))): Switches focus to a frame based on both ID and title attributes
using XPath.
54. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='frameName'][not
(@src='excludedSrc')]"))): Switches focus to a frame based on name and excludes specific
src using XPath.
55. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='frameClass'][not(
@title='excludedTitle')]"))): Switches focus to a frame based on class and excludes specific
title using XPath.
56. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@id,
'frameIdSubstring')]"))): Switches focus to a frame based on an ID substring match using
XPath.
SELENIUM COMMANDS
57. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@class,
'frameClassSubstring')]"))): Switches focus to a frame based on a class substring match
using XPath.
58. driver.switchTo().frame(driver.findElement(By.xpath("//iframe[starts-with(@id,
'frameIdPrefix')]"))): Switches focus to a frame based on a prefix match of the ID attribute
using XPath.
Alert Commands
Wait Commands
46. wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Help']"))):
Waits until the link with text 'Help' is clickable.
47. wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@type='text']"))):
Waits until the text input field element located by XPath is clickable.
48. wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("input[type='pass
word']"))): Waits until the password input field is visible.
49. wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@na
me='frame']"))): Waits until the iframe with name 'frame' is available and switches to it.
50. wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='submit']"))
): Waits until the button with ID 'submit' is clickable.
51. wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("searchField"))): Waits
until the search field element located by name is visible.
1. Actions actions = new Actions(driver): Creates a new Actions instance for performing
advanced user interactions.
2. actions.moveToElement(element).perform(): Moves the mouse to the center of the specified
element and performs the action.
3. actions.click(element).perform(): Clicks on the specified element.
4. actions.doubleClick(element).perform(): Double-clicks on the specified element.
5. actions.contextClick(element).perform(): Performs a right-click on the specified element.
6. actions.clickAndHold(element).perform(): Clicks and holds the specified element.
7. actions.release(element).perform(): Releases the held element.
8. actions.dragAndDrop(source, target).perform(): Drags an element from the source to the
target.
9. actions.sendKeys(Keys.ENTER).perform(): Sends the Enter key to the element.
10. actions.sendKeys(Keys.TAB).perform(): Sends the Tab key to the element.
11. actions.sendKeys(Keys.BACK_SPACE).perform(): Sends the Backspace key to the element.
12. actions.sendKeys(Keys.ESCAPE).perform(): Sends the Escape key to the element.
13. actions.sendKeys(Keys.CONTROL, "a").perform(): Sends Ctrl+A key combination to the
element.
14. actions.sendKeys(Keys.CONTROL, "c").perform(): Sends Ctrl+C key combination to the
element.
15. actions.sendKeys(Keys.CONTROL, "v").perform(): Sends Ctrl+V key combination to the
element.
16. actions.sendKeys(Keys.CONTROL, "x").perform(): Sends Ctrl+X key combination to the
element.
17. actions.moveToElement(element, offsetX, offsetY).perform(): Moves the mouse to the
specified offset from the center of the element.
18. actions.keyDown(Keys.SHIFT).sendKeys("text").keyUp(Keys.SHIFT).perform(): Sends text
with Shift key held down.
19. actions.keyDown(Keys.ALT).sendKeys("text").keyUp(Keys.ALT).perform(): Sends text with
Alt key held down.
20. actions.keyDown(Keys.CONTROL).sendKeys("text").keyUp(Keys.CONTROL).perform():
Sends text with Ctrl key held down.
21. actions.pause(Duration.ofSeconds(2)).perform(): Pauses the execution for 2 seconds.
SELENIUM COMMANDS
1. driver.manage().getCookies(): Retrieves all cookies visible to the current page, which can be
used for session management.
2. driver.manage().getCookieNamed("cookieName"): Retrieves a specific cookie by its name,
useful for checking session data.
3. driver.manage().addCookie(new Cookie("name", "value")): Adds a new cookie, which can be
used to manage session data.
4. driver.manage().deleteCookieNamed("cookieName"): Deletes a specific cookie, useful for
ending a session.
5. driver.manage().deleteCookie(cookie): Deletes a specific cookie object from the session.
6. driver.manage().deleteAllCookies(): Deletes all cookies associated with the current domain,
effectively ending the session.
7. driver.manage().getCookieNamed("cookieName").getName(): Retrieves the name of a
specific cookie for session management.
8. driver.manage().getCookieNamed("cookieName").getValue(): Retrieves the value of a
specific cookie, useful for session validation.
9. driver.manage().getCookieNamed("cookieName").getDomain(): Retrieves the domain of a
specific cookie, important for session scope.
SELENIUM COMMANDS
36. options.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
UnexpectedAlertBehaviour.IGNORE): Ignores unexpected alerts in the browser.
37. options.setCapability("proxy", proxy): Configures a proxy server for browser options.
38. capabilities.setCapability("maxInstances", 5): Sets the maximum number of browser
instances to be run concurrently.
39. capabilities.setCapability("browserName", "firefox"): Sets the browser name to Firefox in
DesiredCapabilities.
40. capabilities.setCapability("browserVersion", "90.0"): Sets the browser version to Firefox
90.0 in DesiredCapabilities.
41. capabilities.setCapability("platformName", "macOS"): Sets the platform (OS) to macOS in
DesiredCapabilities.
42. options.setCapability("browserName", "MicrosoftEdge"): Sets the browser name to
Microsoft Edge.
43. options.setCapability("browserVersion", "latest"): Sets the browser version to the latest
version available.
44. options.setCapability("platformName", "Linux"): Sets the platform (OS) to Linux in
DesiredCapabilities.
45. options.addArguments("start-maximized"): Configures the browser to start maximized by
default.
46. options.addArguments("disable-popup-blocking"): Disables the popup blocking feature in
the browser.
47. options.addArguments("disable-gpu"): Disables GPU hardware acceleration in the browser.
48. options.addArguments("headless"): Runs the browser in headless mode for testing without
a GUI.
49. options.setCapability("acceptInsecureCerts", true): Configures the browser to accept
insecure SSL certificates.
50. options.setCapability("proxy", proxy): Sets up a proxy for the browser.
51. capabilities.setCapability("enableVNC", true): Enables VNC (Virtual Network Computing) for
remote debugging.
52. capabilities.setCapability("enableVideo", true): Enables video recording of the test session.
50. driver.executeScript("return
window.getComputedStyle(document.querySelector('selector')).display"): Returns the
display style property value of the specified element.
1. driver.findElement(By.cssSelector("input[type='file']")).sendKeys("/path/to/file"): Uploads
a file by specifying its path to an input element with type 'file'.
2. driver.findElement(By.id("file-upload")).sendKeys("/path/to/file"): Uploads a file by
specifying its path to an input element with a specific ID.
3. driver.findElement(By.name("file")).sendKeys("/path/to/file"): Uploads a file by specifying
its path to an input element with a specific name.
4. driver.findElement(By.xpath("//input[@type='file']")).sendKeys("/path/to/file"): Uploads a
file using XPath to locate the file input element.
5. driver.findElement(By.cssSelector("input.upload")).sendKeys("/path/to/file"): Uploads a
file by specifying its path to a file input element with a specific class.
6. driver.findElement(By.cssSelector("input[type='file']")).sendKeys("/absolute/path/to/file")
: Uploads a file using the absolute path to the file input element.
7. driver.findElement(By.id("uploadButton")).sendKeys("/path/to/file"): Uploads a file by
specifying its path to an element used for file uploads.
8. driver.findElement(By.xpath("//input[@name='fileUpload']")).sendKeys("/path/to/file"):
Uploads a file using XPath to locate the file input element by its name attribute.
9. driver.findElement(By.cssSelector("input#file-upload")).sendKeys("/path/to/file"):
Uploads a file by specifying its path to an input element with a specific CSS ID.
10. driver.findElement(By.className("file-input")).sendKeys("/path/to/file"): Uploads a file by
specifying its path to an input element with a specific class name.
11. driver.findElement(By.xpath("//input[@id='file-upload']")).sendKeys("/path/to/file"):
Uploads a file using XPath to locate the file input element by its ID.
12. driver.findElement(By.cssSelector("input.file")).sendKeys("/path/to/file"): Uploads a file by
specifying its path to an input element with a specific class name.
13. driver.findElement(By.name("uploadFile")).sendKeys("/path/to/file"): Uploads a file by
specifying its path to an input element with a specific name.
14. driver.findElement(By.id("fileUpload")).sendKeys("/path/to/file"): Uploads a file by
specifying its path to an input element with a specific ID.
15. driver.findElement(By.xpath("//input[contains(@id,
'upload')]")).sendKeys("/path/to/file"): Uploads a file using XPath to locate the file input
element by a partial ID match.
16. driver.findElement(By.cssSelector("input[type='file'][name='fileUpload']")).sendKeys("/pat
h/to/file"): Uploads a file by specifying its path to an input element with both type and
name attributes.
17. driver.findElement(By.cssSelector("input#upload")).sendKeys("/path/to/file"): Uploads a
file by specifying its path to an input element with a specific CSS ID.
18. driver.findElement(By.name("fileUpload")).sendKeys("/path/to/file"): Uploads a file by
specifying its path to an input element with a specific name.
19. driver.findElement(By.className("upload-file")).sendKeys("/path/to/file"): Uploads a file
by specifying its path to an input element with a specific class.
SELENIUM COMMANDS
35. driver.findElement(By.xpath("//xpath")).findElement(By.name("child_name")).getLocation
(): Retrieves the location of a child element using XPath.
36. driver.findElement(By.cssSelector("selector")).findElement(By.className("child_class_nam
e")).isDisplayed(): Checks if a child element is displayed using CSS selector.
37. driver.findElement(By.className("class_name")).findElement(By.cssSelector("child_selecto
r")).isEnabled(): Checks if a child element is enabled using class name.
38. driver.findElement(By.id("element_id")).findElement(By.xpath("//child_xpath")).isSelected
(): Checks if a child element is selected using ID.
39. driver.findElement(By.xpath("//xpath")).findElement(By.linkText("child_link_text")).clear()
: Clears the text from a child element using XPath.
40. driver.findElement(By.cssSelector("selector")).findElement(By.className("child_class_nam
e")).submit(): Submits a child element using CSS selector.
41. driver.findElement(By.className("class_name")).findElement(By.tagName("tag_name")).se
ndKeys("text"): Sends text to a child element using class name.
42. driver.findElement(By.xpath("//xpath")).findElement(By.cssSelector("child_selector")).get
Attribute("attribute_name"): Retrieves the value of an attribute from a child element using
XPath.
43. driver.findElement(By.cssSelector("selector")).findElement(By.tagName("tag_name")).getSi
ze(): Retrieves the size of a child element using CSS selector.
44. driver.findElement(By.className("class_name")).findElement(By.xpath("//child_xpath")).g
etCssValue("property_name"): Retrieves the value of a CSS property from a child element
using class name.
45. driver.findElement(By.id("element_id")).findElement(By.className("child_class_name")).ge
tText(): Retrieves the text from a child element using ID.
46. driver.findElement(By.xpath("//xpath")).findElement(By.tagName("tag_name")).isDisplaye
d(): Checks if a child element is displayed using XPath.
47. driver.findElement(By.cssSelector("selector")).findElement(By.name("child_name")).getTex
t(): Retrieves the text from a child element using CSS selector.
48. driver.findElement(By.className("class_name")).findElement(By.cssSelector("child_selecto
r")).getAttribute("attribute_name"): Retrieves the value of an attribute from a child element
using class name.
49. driver.findElement(By.id("element_id")).findElement(By.xpath("//child_xpath")).getSize():
Retrieves the size of a child element using ID.
50. driver.findElement(By.xpath("//xpath")).findElement(By.linkText("child_link_text")).isEnab
led(): Checks if a child element is enabled using XPath.
51. driver.findElement(By.cssSelector("selector")).findElement(By.name("child_name")).getSiz
e(): Retrieves the size of a child element using CSS selector.
52. driver.findElement(By.className("class_name")).findElement(By.xpath("//child_xpath")).is
Selected(): Checks if a child element is selected using class name.
53. driver.findElement(By.id("element_id")).findElement(By.className("child_class_name")).ge
tCssValue("property_name"): Retrieves the value of a CSS property from a child element
using ID.
SELENIUM COMMANDS