WebdriverIO Interview Questions

Select a Checkbox using WebdriverIO?

We need to follow few steps to make sure that the element is selected or not, Normally when we have this kind of scenario what we do is, we will use click() method to select the check box. After this, we might move on to the next step of the scenario.

Sometimes not selecting will help you, you got to make sure that the checkbox is selected. To verify it we need to use the isSelected() method and get check whether it is really selected.

var checked = $("//input[@type='checkbox']").isSelected()
if(!checked){
	$("//input[@type='checkbox']").click()
}

All the links are formed using anchor tag a and all links will have href attribute with URL value. So by locating elements of tagName 'a' we can find all the links on a webpage.

We can use the following code to get all the links

$$("a")
How to verify tooltip text using WebdriverIO?

Tooltips web elements have an attribute of type title. By fetching the value of the 'title' attribute we can verify the tooltip text in WebdriverIO.

var tooltip = $("some locator").getAttribute("title")
console.log(tooltip)
How to check whether a dropdown is selected or not in angular applications with webdriverIO?

isSelected() verifies if an element is selected or not, isSelected() method returns boolean value, true if the element is selected and false if it is not.

browser.get("https://google.com")
var selectedFlag = $("//input[@id='selected'] [value='Bangalore']").isSelected()
console.log("Is element selected : "+selectedFlag);
How do you accept alerts in WebdriverIO ?

We can accept the alert using acceptAlert()

browser.acceptAlert()
How to Overwrite Current Input Value in the editable field On Page using WebriverIO?

The sendKeys method on WebElement class will append the value to the existing value of the element. If you want to clear the old value. You can use clear() method.

let webElement = $("element-id");
webElement.setValue("new input value");
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions