Handling Dropdown using JSE:
---------------------------
Select tag -- Class --> Select -class
selectByvisibleText()
selectByvalue();
selectByIndexNo();
package JavaScriptexecutorBasics;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class DroddownHandlingUsingJSE {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", ".\\Drivers\\chromedriver.exe");
// //open chrome browser
WebDriver driver = new ChromeDriver();
driver.get("file:///C:/brahma/Practise/qtp%20practise/web%20apps/ALL%20Web%20objects.html");
// if dropdown is developed by using 'Select' tags --- 'Select' class methods
// SelectbyVisibleText() , Selectbyvalue(), SelectbyIndex();
// some times, these methods will not work
// select first option in 'cars' dropdown using indexno
// JS code--> document.getElementsByName('cars')[0].selectedIndex = 0;
//HW js code
Thread.sleep(3000);
//HW select 'Maruthi' based on index no ?
Thread.sleep(3000);
//HW select 2nd option in cars dropdown using
//js code-->
// select Swiftvdi
// HW select 3rd option in cars dropdown using index no
// HW select 4th option in cars dropdown using index no
// get selected value indexno from dropdown
//JS Code-->
//HW
// get dropdown values count :
// JS code: document.getElementsByName('cars')[0].options.length;// 6
// HW
// Get first dropdown Value :i.e Maruthi
// JS code: document.getElementsByName('cars')[0].options[0].innerText;
// HW
// HW get 2nd, 3rd dropdown value SwiftVDI, Mercedes
//HW WAP get all dropdown values -
// Js code :document.getElementsByName('cars')[0].options[0].innerText;
// Js code :document.getElementsByName('cars')[0].options[1].innerText;
// js code :document.getElementsByName('cars')[0].options[2].innerText;
// ........................
//..........................................................5
// way2: Select dropdown value using by value
//JS code document.getElementsByName('cars')[0].value= 'Swiftvdival';
//HW
// HW select diff Mercedes, audi, BMW using value ?
// HW Select dropdown value using visible text ??????????????? Search ??? not any method
}
}
No comments:
Post a Comment