Note| Text in Blue [#PYTHON] and Orange [#JAVA] can be edited or mentioned important for the entire blog. All the posts are practically done by me.
In PageFactory, by default you don't need to specify the Locator type for Name and ID; Instead initialize the weblements using the below simple format.
private WebElement gbqfq; // here, 'gbqfq' is a name
private WebElement q; // here, 'q' is an id
gbqfq.sendKeys("Prashanth Sams");
or|
q.sendKeys("Prashanth Sams");
Lets see with an example,
Google TC | GoogleTest.java
package packagename;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class GoogleTest {
private WebDriver driver;
@BeforeTest
public void setUp() throws Exception {
driver = new FirefoxDriver();
}
@Test
public void Test01() throws Exception{
GoogleSearch page = PageFactory.initElements(driver, GoogleSearch.class);
page.searchFor("Prashanth Sams");
}
@AfterTest
public void Teardown() throws Exception{
driver.quit();
}
}
Google Search | GoogleSearch.java
package packagename;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class GoogleSearch {
private WebElement q; // Here's the Element
public WebDriver driver;
public GoogleSearch(WebDriver driver) {
this.driver = driver;
driver.get("http://www.google.com/");
}
public void searchFor(String text) {
q.sendKeys(text);
q.submit();
}
}
Working with Annotation | @FindBy
@FindBy and @FindBys lets you find elements using the locators. @FindBys plays a major role in finding elements.
Google Search | GoogleSearch.java
#USING @FindBy
package packagename;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
public class GoogleSearch {
@FindBy(how = How.NAME, using = "q") // or use @FindBy(name = "q")
@CacheLookup // keeps the element in cache for rapid execution
private WebElement searchme;
@FindBy(id = "gbqfq") // Less Verbose
private WebElement submitme;
//Here, both searchme & submitme refers to the same element
public WebDriver driver;
public GoogleSearch(WebDriver driver) {
this.driver = driver;
driver.get("http://www.google.com/");
}
public void searchFor(String text) {
searchme.sendKeys(text);
submitme.submit();
}
}
#USING @FindBys
package packagename;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.FindBys;
public class GoogleSearch {
@FindBys({@FindBy(id = "gs_lc0"), @FindBy(name = "q")})
@CacheLookup // keeps the element in cache for rapid execution
private WebElement searchme;
public WebDriver driver;
public GoogleSearch(WebDriver driver) {
this.driver = driver;
driver.get("http://www.google.com/");
}
public void searchFor(String text) {
searchme.sendKeys(text);
searchme.submit();
}
}
It was very nice article and it is very useful to Selenium learners.We also provide Cub training software online training.
ReplyDeleteEverything is fine, am happy about your blog. Thanks admin for sharing the unique content, you have done a great job I appreciate your effort.
ReplyDeleteSelenium training in chennai
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteamazon-web-services training in chennai
Thanks for the great information in your blog.
ReplyDeletejava training in chennai
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteios training in chennai
Thanks for the great information in your blog.
ReplyDeletesoapui training in chennai
Thanks for sharing this post it is really useful.
ReplyDeleteBest Selenium Training in Chennai
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.
ReplyDeleteRegards,
Best Oracle DBA Online Training Institute By Real Time Faculties
This comment has been removed by the author.
ReplyDeleteGreat article with an excellent idea!Thank you for such a valuable article. I really appreciate for this great information.
ReplyDeleteBest Selenium Training Institute in Chennai
Selenium training institute in Chennai
Selenium Training Chennai
Selenium Training in Anna Nagar
Selenium Training in Tambaram
Thanks for sharing these effective tips. It was very helpful for me.
ReplyDeleteIELTS Institute in Mumbai
Best IELTS Coaching Classes in Mumbai
IELTS Coaching Center in Mumbai
Best IELTS Classes in Mumbai
IELTS Coaching near me
IELTS Course in Mumbai
IELTS Training Institute in Mumbai
Thanks for your sharing
ReplyDeleteDevOps Training in Chennai
Cloud Computing Training in Chennai
IT Software Training in Chennai
3. if you want girls mobile numbers then this website is best for you . you can visit on this website and get their information and you also can meet with thrm and go for a date . click here to use our website --- online dating website
ReplyDelete2. if you are searching for free unlimted tricks then visit now on Uvoffer.com and get unlimited offers and informations.
ReplyDeletefilm ka naam whatsapp puzzle answer 🐵🐵🐵 +🐘+3+🏹+🏚+💔 =
1. many peoples want to join random whatsapp groups . as per your demand we are ready to serve you whatsapp group links . On this website you can join unlimited groups . click and get unlimited whatsapp group links 18+ america
ReplyDeletehey guys goviral here want to know about goatfarming click here
ReplyDeletegoviral
goat farming
hey guys if you to know about bikes news like bullet r15 pulser and all modified bike here
ReplyDeleteYamaha Rx100 modified
mini Bullet 200cc
splendor modified pictures
know about Traffic rules
Pulsar 220 modified
Tvs Radeon full review
Welcome to Biksdna.com clcik here
I wanted to build my career in IT. Hats-off to the trainers at the training centre. They provide complete assistance and always ready to guide.
ReplyDeletecloud computing training institutes in bangalore
cloud computing training in bangalore
best cloud computing training institutes in bangalore
cloud computing training course content
cloud computing training interview questions
cloud computing training & placement in bangalore
cloud computing training center in bangalore
Really i found this article more informative, thanks for sharing this article! Also Check here
ReplyDeleteCCC Previous Year Question Paper
Thanks for sharing information awesome blog post Online Education Quiz website For Exam Follow this website Gk in Hindi
ReplyDelete
ReplyDeleteExcellent Blog I like your blog and It is very informative. Thank you
Puppet Course Online
selenium online training
Linux Online Training
Awesome Blog!!! Thanks for it, it is more useful for us
ReplyDeleteAWS Training in Tambaram
AWS Training in Anna Nagar
AWS Training in Velachery
AWS Training in Tnagar
AWS Training in Porur
AWS Training in OMR
AWS Training in Chennai
The Blog contains the effective and attractive information’s and thanks for the blog.
ReplyDeleteJava Training Institute in Chennai
JAVA Training Institute in Bangalore
이 웹 사이트는 내가이 주제에 대해 원했던 모든 정보를 가지고 있고 누구에게 물어봐야할지 몰랐습니다.메이저놀이터
ReplyDelete공유해 주셔서 감사합니다!
Shop for the latest Redmi mobiles from Helmet Don at the best prices in India. Xiaomi smartphones include Mi Series, Mi Note Series, Redmi Series, Pocophone, Mi Max Series, Mi Mix Series, and the Blackshark.
ReplyDeleteHelmetDon
dslr-camera
oppo-phones
Login Your TriumphFX Account. Read In Depth TriumphFX Review.
ReplyDeleteExtraordinary Blog. Provides necessary information.
ReplyDeleteProtractor Training
Protractor Course
hi thanku so much this information this blog is very useful
ReplyDeletecs executive
freecseetvideolectures/
AximTrade Is A Forex And Cfd Broker. It Offers Trading In Currency Pairs, Commodities, Indices, And Shares. It Also Provides A Range Of Tools, And 24/7 Customer Service. Sign Up For Aximtrade Login Account Today!
ReplyDeleteVisit Aximtrade Mt4 Download Login To View Your Personal Area Where You Can Manage Your Trading Accounts, Set Up Your Watchlist, And Track Your Recent Trades.
ReplyDeleteThank you for sharing this valuable information with us.
ReplyDeleteGirvi Software
Girvi Software
betmatik
ReplyDeletekralbet
betpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
L5XK
thanks for sharing information awesome blog post
ReplyDeleteJewellery ERP Software Dubai
Jewellery ERP Software Dubai