Tuesday 3 January 2017

Working with Dropdowns with selenium

// small example to demonstrate working with selenium webdriver and drop downs
package selenium.dropdowns;import java.util.Iterator;import java.util.List;import org.openqa.selenium.By;import org.openqa.selenium.WebElement;import org.openqa.selenium.chrome.ChromeDriver;import org.openqa.selenium.support.ui.Select;public class dd { public static void main(String[] args) throws InterruptedException {  System.setProperty("webdriver.chrome.driver", "C:\\Users\\shama.ugale\\Downloads\\chromedriver.exe");  ChromeDriver driver= new ChromeDriver();     driver.get("https://www.commonfloor.com/agent/login?show_signup=1");    WebElement cityDD=driver.findElement(By.id("city"));    ///////// use case 1 - select any elem in the dd  Select sec= new Select(cityDD);    sec.selectByIndex(45);  Thread.sleep(2000);    // this is the value attribute of the option element under ur dropdown  sec.selectByValue("Ghaziabad");  Thread.sleep(2000);    sec.selectByVisibleText("Pune");      ///////////// use case 2 -- fetch all the dd elements          List<WebElement> cities= sec.getOptions();    Iterator<WebElement> it= cities.iterator();  while(it.hasNext()){   WebElement elem= it.next();   System.out.println(elem.getText());  }    //////////////// use case 3 --- size of the elements    System.out.println("No of cities : " + cities.size());      /////////////// use case 4 -- fetch wats selected in the dd    String selectedValue=sec.getFirstSelectedOption().getText();    System.out.println("Selected option : "+ selectedValue);               }}

21 comments:

  1. Selenium Framework Training in Chennai

    Reach @ 8122241286 or 9003085882

    http://thecreatingexperts.com/selenium-training-in-chennai/

    Best in Class Advanced Selenium Framework based Training in Chennai with live project EXP.

    ReplyDelete
  2. Great post. I am actually getting ready to across this information, its very helpful for this blog. Also great with all of the valuable information you have keep up the good work you are doing well. Selenium Training in Chennai

    ReplyDelete
  3. Hello Shama,
    The Article on Working with Dropdowns with selenium
    is nice give detail information about it.Thanks for Sharing the information about Testing with Selenium Software Testing Company

    ReplyDelete
  4. Great information it's very useful for freshers. I read your blog completely I gather lot of information in this blog.It will help me to analyses lot of information about selenium. Thank you for sharing!
    Best Selenium Training in chennai

    ReplyDelete
  5. Thanks for sharing such a valuable information. It was very nice and also informative. Keep giving like this.
    Best Data Science Online Training Institute In Hyderabad

    ReplyDelete
  6. Awesome blog. It was very informative. I would like to appreciate you. Keep updated like this best selenium training institute in hyderabad

    ReplyDelete
  7. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information... Java Training in Chennai | Blue prism Training in Chennai

    ReplyDelete
  8. WOW! Really Nice Post! I personally believe that to maintain the standard of a blog all the hacks mentioned above are important. All points discussed were worth reading
    and I’ll surely work with them all one by one.

    CEH Training In Hyderbad

    ReplyDelete
  9. Really a good post, thanks for sharing .keep it up.
    Jewellery ERP Software Dubai
    Jewellery ERP Software Dubai

    ReplyDelete
  10. Really a good post, thanks for sharing .keep it up.
    Jewellery Software
    Jewellery Software

    ReplyDelete