Long back i saw some post from Dave Haeffner and he is writer of Elemental Selenium -- a free, once weekly Selenium tip newsletter that's read by thousands of testing professionals, also the author of The Selenium Guidebook; a guide on how to use Selenium successfully.
I am receiving some weekly tips from Dave Haeffner's site and those are in Ruby language. i want to rewrite them in Java. Using Selenium webdriver + TestNg + Java
Problem:
On occasion you may have the need to check if an element on a page is disabled or enabled. Sounds simple enough, but how do you do it?
Solution:
We have a available method called isEnabled(). which will help us in resolving the above problem.
I am receiving some weekly tips from Dave Haeffner's site and those are in Ruby language. i want to rewrite them in Java. Using Selenium webdriver + TestNg + Java
Problem:
On occasion you may have the need to check if an element on a page is disabled or enabled. Sounds simple enough, but how do you do it?
Solution:
We have a available method called isEnabled(). which will help us in resolving the above problem.
isEnabled
boolean isEnabled()
Is the element currently enabled or not? This will generally return true for everything but disabled input elements.- Returns:
- True if the element is enabled, false otherwise.
package sample; import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class Enable_test { public WebDriver driver; @Test public void testEnable_test() throws Exception { driver.get("http://the-internet.herokuapp.com"); driver.findElement(By.linkText("Dropdown")).click(); List<WebElement> dropdown=driver.findElements(By.xpath("//select[@id='dropdown']/option")); for (int i = 0; i < dropdown.size(); i++) { if(dropdown.get(i).getText()=="Please select an option") { //assert false will always expects false value. //Here option is disabled so it will return false Assert.assertFalse(dropdown.get(i).isEnabled()); } } } @BeforeClass public void beforeClass() { driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } @AfterClass public void afterClass() throws Exception { driver.quit(); } }
Thanks for your post; selenium is most trusted automation tool to validate web application and browser. This tool provides precise and complete information about a software application or environment.
ReplyDeleteRegards,
Best Selenium Training Institute in Chennai
Selenium is a portable software testing framework for web applications. Selenium provides a record/playback tool for authoring tests without learning a test scripting language (Selenium IDE).Selenium IDE is an integrated development environment for Selenium tests.
ReplyDeleteRegards,
Selenium training institute in Chennai | Selenium training Chennai
Thank you for sharing in this article, I can learn a lot and could also be a reference, I hope to read the next your article updates.
ReplyDeleteSoftware Testing Training in chennai | Testing Training in chennai
This blog was very interesting with good guidance, it is very helpful for developing my skill. I eagerly for your more posts, keep sharing...!
ReplyDeleteOracle DBA Training in Chennai
Oracle DBA Course in Chennai
Spark Training in Chennai
Oracle Training in Chennai
Linux Training in Chennai
Social Media Marketing Courses in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Power BI Training in Chennai
Tableau Training in Chennai