Highlight element with Selenium Webdriver

Here is the code to highlight the element using Selenium Webdriver. You will have to replace the driver.findElement to findElement. I have also give the example of using findElement.

public WebElement findElement(By by) {
WebElement elem = driver.findElement(by);
if (driver instanceof JavascriptExecutor) {
((JavascriptExecutor) driver).executeScript("arguments[0].style.border='1px solid yellow'", elem);
}
return elem;
}


public void type(By by, String value) throws InterruptedException {
try {
findElement(by).clear();
findElement(by).sendKeys(value);
} catch (Exception e) {
waitForSpinner();
findElement(by).clear();
findElement(by).sendKeys(value);
}
}

Resolving – Element is not clickable at point

Here is a simple solution to resolve the Element is not clickable at point issue with ChromeDriver in Webdriver.
Here is the function I have written to detect the browser and then pause for .5 sec before executing the next command.

public bool CheckElementPresent(string Xpath)
{
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string ibrowser = (string)js.ExecuteScript("return " + "navigator.userAgent");
if (ibrowser.Contains("Chrome"))
{
Thread.Sleep(500);
}
bool present = false;
for (int second = 0; ; second++)
{
if (second >= 10)
{
break;
}
if (IsElementPresent(Xpath))
{
present = true;
break;
}
Thread.Sleep(1000);
}
return present;
}

Here is the code where I have used the function:
//click view more link
CheckElementPresent(ViewmoreCategory_lnk);
Click(ViewmoreCategory_lnk);
//click add another keywords link
CheckElementPresent(AddAnotherHyperLink);
Click(AddAnotherHyperLink);

I hope this will be useful for you.

Using JavascriptExecutor to type text in a rich text editor box

This is a solution for the Selenium Webdriver Type command not working on IE when you are trying to enter some text in a rich text editor. You can use the below code to execute the command in IE and other browsers.

((JavascriptExecutor)driver).executeScript("document.getElementById('ElementID').value='TextValue'");

The rich text editor is usually placed in a iFrame.