Exception in thread "main" java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolver



This error occurs when you are using old version of http client jar.



You can use below dependency for maven:

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.2</version>
</dependency>

Handle windows with Selenium:

 There are test cases in which we need to switch between multiple windows, to automate these test cases using selenium we need to use below functions:
1.getWindowHandle(): This function return parent window reference.
2.getWindowHandles() : This function return all windows reference.
3.switchTo().window(Window) : This function used to switch between windows.
Example:
String Parent_Window = driver.getWindowHandle();
for (String Child_Window : driver.getWindowHandles())
{
driver.switchTo().window(Child_Window);
driver.findElement(By.id("appointment")).click();
driver.findElement(By.id("closeAppointment")).click();
driver.close();
}

driver.switchTo().window(Parent_Window);

Handling Frames in Selenium:

Selenium has multiple methods to handle Frames.
  1. driver.switchTo().frame(name) 
  2. driver.switchTo().frame(id) 
  3. driver.switchTo().frame(index) 
  4. driver.switchTo().frame(iframe_element) 
Example:
<iframe name=”content” id=”contentSection”></iframe>
Multiple options:

driver.switchTo.frame(“content”);
driver.switchTo.frame(“contentSection”);
driver.switchTo.frame(0);
driver.switchTo.frame(driver.findElement(By.cssSelector("iframe[id='contentSection']")
)


To get out of Frame:
driver.SwitchTo().DefaultContent()
Switch to Parent Frame:
driver.switchTo().parentFrame();



Handling keyboard events and mouse actions:

Action class is used to handle keyboard events and mouse actions. Further this class is also used to chain actions or perform multiple actions.

Action name Parameters Description
click WebElement This is used to click in the middle of the element passed as parameter. Like action.click(webelement)
click No Parameter This is used to click at the current location. It is used with combination of actions.
Like action.moveToElement(org.openqa.selenium.WebElement, int, int).click() or action.moveByOffset(int, int).click()
doubleClick WebElement This is used to double click in the middle of the element passed as parameter. Like action.doubleClick(webelement)
doubleClick No Parameter This is used to double click at the current location. It is used with combination of actions.
Like action.moveToElement(org.openqa.selenium.WebElement, int, int).doubleClick() or action.moveByOffset(int, int).doubleClick()
moveToElement WebElement This is used to move mouse pointer to the middle of webelement passed as parameter. The element is scrolled into view. Like action.moveToElement(webelement)
moveToElement WebElement, int, int This is used to move the mouse pointer to offsets from the top left corner of element.The element is scrolled into view. Example: action.moveToElement(webelement, int, int)
moveByOffset int, int This is used to move mouse pointer from current position to the provided offsets. Example: action.moveByOffset(int, int)
keyDown java.lang.CharSequence This is used to perform key press. Remember key is not released automatically, Need to call keyUp() or sendKeys() function. Example: action.keyDown(keys.CONTROL)
keyDown WebElement, java.lang.CharSequence This is used to press key at web element. Example: action.keyDown(webelement, keys.CONTROL)
keyUp Java.lang.CharSequence This is used to keup or release key at current location. Example: action.keyUp(keys.CONTROL)
KeyUp WebElement, Java.lang.CharSequence This is used to press up at web element. Example: action.keyUp(webelement, keys.CONTROL)
sendKeys java.lang.CharSequence This is used to send keys on active element. Example: action.sendKeys(Keys.TAB)
clickAndHold WebElement Click on current mouse location without releasing.
contextClick WebElement Right click on web element. Example: action.contextClick(webelement)
dragAndDrop WebElement, WebElement Perform drag and drop from one element to other.
dragAndDropBy WebElement, int, int Perform drag and drop from one element to co-ordinates.
build No Parameter Used to combine multiple actions into single step. Example:
Actions oAction=new Actions(driver);
Actions moreActions = oAction
.moveToElement(element)
.click()
.keyDown(element,Keys.SHIFT)
.sendKeys(element,"selenium");

Action chaining= moreActions.build();
perform No Parameter For execution of Action object, this method is used. Example:
chaining.perform();

Handling drop-down with Selenium

Selenium Select class is used to perform actions on drop-down:
Different functions provided by Select class:


selectByVisibleText()/deselectByVisibleText()
selects or deselects an option by its visible text from drop down
selectByValue()/deselectByValue()
selects or deselects an option by the value displayed for "value" attribute
selectByIndex()/deselectByIndex()
selects or deselects an option by its index
isMultiple()
returns TRUE if the drop-down allows multiple selection at a time and return FALSE if not allowed
deselectAll()
deselects all selected options



Sample Code:
WebElement dropdown = driver.findElement(By.name("dropdown"));
Select select = new Select(dropdown);

// Here we will perform the multiselect operation in the dropdown.
select.selectByVisibleText("John");

The project was not built since its build path is incomplete eclipse java maven

For those encountering this error while using Maven:

    Right click on the project, Build Path -> Configure Build Path...
    Select the libraries tab. If Maven dependencies is not in the list, you have identified the problem.
    Close the dialog.
    Right click on the project, Maven -> Disable Maven Nature
    Right click on the project, Configure -> Convert to Maven Project.