How to verify specific web element on different page in login moduleHow do I generate random integers within a specific range in Java?How to verify that a specific method was not called using Mockito?How to check the username is validNot able to verify text after login with selenium Webdriver scriptI am unable to click on a Web Element using Selenium Webdriverselenium Test case for facebook login and logoutSelenium : Unable to Retrieve WebElements Stored in MapHow to click the elements insde <md-dailoge-container> angularjs 2 element in seleniumTrying to return the text value of a classHow to use CssSelectors
Can I play a mimic PC?
Having decision making power over someone's assets
"was fiction" vs "were fictions"
Why does the Antonov AN-225 not have any winglets?
What's the point of having a RAID 1 configuration over incremental backups to a secondary drive?
Yet another hash table in C
Misspelling my name on my mathematical publications
What is this little owl-like bird?
Should I include code in my research paper?
Why does every calorie tracking app give a different target calorie count for the same goals?
Can Jimmy hang on his rope?
Is that a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?
To what extent would a wizard be able to combine feats to learn to mimic unknown spells?
Distinguish the explanations of Galadriel's test in LotR
Why is a mixture of two normally distributed variables only bimodal if their means differ by at least two times the common standard deviation?
Can i use larger/smaller circular saw blades on my circular / plunge / table / miter saw?
What happens to unproductive professors?
Swapping "Good" and "Bad"
Is it possible to split a vertex?
Did the Ottoman empire suppress the printing press?
Why archangel Michael didn't save Jesus when he was crucified?
What attributes and how big would a sea creature(s) need to be able to tow a ship?
Credit score and financing new car
How to design a CMC (Common Mode Choke) footprint to allow no-pop solution
How to verify specific web element on different page in login module
How do I generate random integers within a specific range in Java?How to verify that a specific method was not called using Mockito?How to check the username is validNot able to verify text after login with selenium Webdriver scriptI am unable to click on a Web Element using Selenium Webdriverselenium Test case for facebook login and logoutSelenium : Unable to Retrieve WebElements Stored in MapHow to click the elements insde <md-dailoge-container> angularjs 2 element in seleniumTrying to return the text value of a classHow to use CssSelectors
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
In my application when user login first time then on first page username is displayed (data driven approach using @factory). But if user logs out and log in again then a new pages comes with following text.
You're signed out now.
Click here to sign in again.
My question is how to check if this text -'Click Here' present then click on it and do same actions as mentioned in login function.
I tried to implement if-else block to check if this webelement is displayed then click on it and do same action as in login function. But it is giving error that
org.openqa.selenium.NoSuchElementException: Cannot locate an element using xpath=//a[@href='/Account/Login']
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Though I'm successfully able to achieve my result by specifying this element to click in Logout function. But when finally my test gets finished it always clicks on it.
@FindBy(xpath="//a[@href='/Account/Login']")
WebElement clickHere;
//function to check
if (clickHere.isDisplayed())
clickHere.click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
Please suggest a solution to check in login function everytime.
java selenium-webdriver data-driven
add a comment |
In my application when user login first time then on first page username is displayed (data driven approach using @factory). But if user logs out and log in again then a new pages comes with following text.
You're signed out now.
Click here to sign in again.
My question is how to check if this text -'Click Here' present then click on it and do same actions as mentioned in login function.
I tried to implement if-else block to check if this webelement is displayed then click on it and do same action as in login function. But it is giving error that
org.openqa.selenium.NoSuchElementException: Cannot locate an element using xpath=//a[@href='/Account/Login']
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Though I'm successfully able to achieve my result by specifying this element to click in Logout function. But when finally my test gets finished it always clicks on it.
@FindBy(xpath="//a[@href='/Account/Login']")
WebElement clickHere;
//function to check
if (clickHere.isDisplayed())
clickHere.click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
Please suggest a solution to check in login function everytime.
java selenium-webdriver data-driven
add a comment |
In my application when user login first time then on first page username is displayed (data driven approach using @factory). But if user logs out and log in again then a new pages comes with following text.
You're signed out now.
Click here to sign in again.
My question is how to check if this text -'Click Here' present then click on it and do same actions as mentioned in login function.
I tried to implement if-else block to check if this webelement is displayed then click on it and do same action as in login function. But it is giving error that
org.openqa.selenium.NoSuchElementException: Cannot locate an element using xpath=//a[@href='/Account/Login']
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Though I'm successfully able to achieve my result by specifying this element to click in Logout function. But when finally my test gets finished it always clicks on it.
@FindBy(xpath="//a[@href='/Account/Login']")
WebElement clickHere;
//function to check
if (clickHere.isDisplayed())
clickHere.click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
Please suggest a solution to check in login function everytime.
java selenium-webdriver data-driven
In my application when user login first time then on first page username is displayed (data driven approach using @factory). But if user logs out and log in again then a new pages comes with following text.
You're signed out now.
Click here to sign in again.
My question is how to check if this text -'Click Here' present then click on it and do same actions as mentioned in login function.
I tried to implement if-else block to check if this webelement is displayed then click on it and do same action as in login function. But it is giving error that
org.openqa.selenium.NoSuchElementException: Cannot locate an element using xpath=//a[@href='/Account/Login']
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Though I'm successfully able to achieve my result by specifying this element to click in Logout function. But when finally my test gets finished it always clicks on it.
@FindBy(xpath="//a[@href='/Account/Login']")
WebElement clickHere;
//function to check
if (clickHere.isDisplayed())
clickHere.click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
Please suggest a solution to check in login function everytime.
java selenium-webdriver data-driven
java selenium-webdriver data-driven
edited Mar 26 at 0:44
Samy
asked Mar 26 at 0:01
SamySamy
488 bronze badges
488 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
clickHere.isDisplayed()
is giving NoSuchElementException
as the element is not present on the UI on which you are trying to find it.
So, to solve your problem you can fetch the list of the element through pagefactory and then can find the size of that list, if the size is greater than 0, it means the element is present on the page else the element is not present.
You need to make the following changes in your code and it would work fine then:
You need to fetch the element list using:
@FindAllBy(xpath="//a[@href='/Account/Login']")
List<WebElement> clickHere;
And make the following changes in your code:
if (clickHere.size()>0)
clickHere.get(0).click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
thanks for the response. I did same as you mentioned but after typing clickHere. - it is not populating 'click' action.
– Samy
Mar 26 at 3:36
@Samy yeah i made a little mistake in my code. Please try the updated code. It should work fine.
– Sameer Arora
Mar 26 at 5:36
yes it is working fine now..but only problem is that it takes lot of time to start login first..may be because of implicit wait which I applied before starting my project...can we do something to start as in normal time interval.
– Samy
Mar 28 at 3:34
@Samy The condition to check if the list size is great than 0 does take some time when the element is not present on the page because it first finds the element on the whole page and then wait for the implicit wait as well and then it sends that the list size is equal to 0. However it would work real fast when the element is present on the page. So there is nothing that we can do about it, you can decrease your implicit wait if your other elements are not getting affected.
– Sameer Arora
Mar 28 at 3:38
add a comment |
Replace the (clickHere.isDisplayed())
with below.
if(driver.findElements(By.xpath("//a[@href='/Account/Login']") ).size() != 0)
if you want to stick to your pagefactory then you can use the below approach
// below line will click on the "Click Here" link if only it's present
try clickHere.click();catch(Exception e)
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
if you would like to catch only NoSuchElementPresent
exception you can update to catch only that.
add a comment |
You can create BaseClass for you PageObject and impelent metchod isElementOnPage
Base class:
public class BasePage
private WebDriver driver;
public BasePage(WebDriver driver)
this.driver = driver;
PageFactory.initElements(driver, this);
protected boolean isElementOnPage(WebElement webElement)
try
webElement.getTagName();
catch (Exception e)
return false;
return true;
Your Class:
public class PageClass extends BasePage
@FindBy(xpath="//a[@href='/Account/Login']")
private WebElement clickHere;
public PageClass(WebDriver driver)
super(driver);
public PageClass YourMethod()
if(isElementOnPage(clickHere))
clickHere.click();
// your logic here
else
// your logic here
return this;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348059%2fhow-to-verify-specific-web-element-on-different-page-in-login-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
clickHere.isDisplayed()
is giving NoSuchElementException
as the element is not present on the UI on which you are trying to find it.
So, to solve your problem you can fetch the list of the element through pagefactory and then can find the size of that list, if the size is greater than 0, it means the element is present on the page else the element is not present.
You need to make the following changes in your code and it would work fine then:
You need to fetch the element list using:
@FindAllBy(xpath="//a[@href='/Account/Login']")
List<WebElement> clickHere;
And make the following changes in your code:
if (clickHere.size()>0)
clickHere.get(0).click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
thanks for the response. I did same as you mentioned but after typing clickHere. - it is not populating 'click' action.
– Samy
Mar 26 at 3:36
@Samy yeah i made a little mistake in my code. Please try the updated code. It should work fine.
– Sameer Arora
Mar 26 at 5:36
yes it is working fine now..but only problem is that it takes lot of time to start login first..may be because of implicit wait which I applied before starting my project...can we do something to start as in normal time interval.
– Samy
Mar 28 at 3:34
@Samy The condition to check if the list size is great than 0 does take some time when the element is not present on the page because it first finds the element on the whole page and then wait for the implicit wait as well and then it sends that the list size is equal to 0. However it would work real fast when the element is present on the page. So there is nothing that we can do about it, you can decrease your implicit wait if your other elements are not getting affected.
– Sameer Arora
Mar 28 at 3:38
add a comment |
clickHere.isDisplayed()
is giving NoSuchElementException
as the element is not present on the UI on which you are trying to find it.
So, to solve your problem you can fetch the list of the element through pagefactory and then can find the size of that list, if the size is greater than 0, it means the element is present on the page else the element is not present.
You need to make the following changes in your code and it would work fine then:
You need to fetch the element list using:
@FindAllBy(xpath="//a[@href='/Account/Login']")
List<WebElement> clickHere;
And make the following changes in your code:
if (clickHere.size()>0)
clickHere.get(0).click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
thanks for the response. I did same as you mentioned but after typing clickHere. - it is not populating 'click' action.
– Samy
Mar 26 at 3:36
@Samy yeah i made a little mistake in my code. Please try the updated code. It should work fine.
– Sameer Arora
Mar 26 at 5:36
yes it is working fine now..but only problem is that it takes lot of time to start login first..may be because of implicit wait which I applied before starting my project...can we do something to start as in normal time interval.
– Samy
Mar 28 at 3:34
@Samy The condition to check if the list size is great than 0 does take some time when the element is not present on the page because it first finds the element on the whole page and then wait for the implicit wait as well and then it sends that the list size is equal to 0. However it would work real fast when the element is present on the page. So there is nothing that we can do about it, you can decrease your implicit wait if your other elements are not getting affected.
– Sameer Arora
Mar 28 at 3:38
add a comment |
clickHere.isDisplayed()
is giving NoSuchElementException
as the element is not present on the UI on which you are trying to find it.
So, to solve your problem you can fetch the list of the element through pagefactory and then can find the size of that list, if the size is greater than 0, it means the element is present on the page else the element is not present.
You need to make the following changes in your code and it would work fine then:
You need to fetch the element list using:
@FindAllBy(xpath="//a[@href='/Account/Login']")
List<WebElement> clickHere;
And make the following changes in your code:
if (clickHere.size()>0)
clickHere.get(0).click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
clickHere.isDisplayed()
is giving NoSuchElementException
as the element is not present on the UI on which you are trying to find it.
So, to solve your problem you can fetch the list of the element through pagefactory and then can find the size of that list, if the size is greater than 0, it means the element is present on the page else the element is not present.
You need to make the following changes in your code and it would work fine then:
You need to fetch the element list using:
@FindAllBy(xpath="//a[@href='/Account/Login']")
List<WebElement> clickHere;
And make the following changes in your code:
if (clickHere.size()>0)
clickHere.get(0).click();
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
else
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
edited Mar 26 at 3:50
answered Mar 26 at 3:20
Sameer AroraSameer Arora
2,3082 gold badges3 silver badges15 bronze badges
2,3082 gold badges3 silver badges15 bronze badges
thanks for the response. I did same as you mentioned but after typing clickHere. - it is not populating 'click' action.
– Samy
Mar 26 at 3:36
@Samy yeah i made a little mistake in my code. Please try the updated code. It should work fine.
– Sameer Arora
Mar 26 at 5:36
yes it is working fine now..but only problem is that it takes lot of time to start login first..may be because of implicit wait which I applied before starting my project...can we do something to start as in normal time interval.
– Samy
Mar 28 at 3:34
@Samy The condition to check if the list size is great than 0 does take some time when the element is not present on the page because it first finds the element on the whole page and then wait for the implicit wait as well and then it sends that the list size is equal to 0. However it would work real fast when the element is present on the page. So there is nothing that we can do about it, you can decrease your implicit wait if your other elements are not getting affected.
– Sameer Arora
Mar 28 at 3:38
add a comment |
thanks for the response. I did same as you mentioned but after typing clickHere. - it is not populating 'click' action.
– Samy
Mar 26 at 3:36
@Samy yeah i made a little mistake in my code. Please try the updated code. It should work fine.
– Sameer Arora
Mar 26 at 5:36
yes it is working fine now..but only problem is that it takes lot of time to start login first..may be because of implicit wait which I applied before starting my project...can we do something to start as in normal time interval.
– Samy
Mar 28 at 3:34
@Samy The condition to check if the list size is great than 0 does take some time when the element is not present on the page because it first finds the element on the whole page and then wait for the implicit wait as well and then it sends that the list size is equal to 0. However it would work real fast when the element is present on the page. So there is nothing that we can do about it, you can decrease your implicit wait if your other elements are not getting affected.
– Sameer Arora
Mar 28 at 3:38
thanks for the response. I did same as you mentioned but after typing clickHere. - it is not populating 'click' action.
– Samy
Mar 26 at 3:36
thanks for the response. I did same as you mentioned but after typing clickHere. - it is not populating 'click' action.
– Samy
Mar 26 at 3:36
@Samy yeah i made a little mistake in my code. Please try the updated code. It should work fine.
– Sameer Arora
Mar 26 at 5:36
@Samy yeah i made a little mistake in my code. Please try the updated code. It should work fine.
– Sameer Arora
Mar 26 at 5:36
yes it is working fine now..but only problem is that it takes lot of time to start login first..may be because of implicit wait which I applied before starting my project...can we do something to start as in normal time interval.
– Samy
Mar 28 at 3:34
yes it is working fine now..but only problem is that it takes lot of time to start login first..may be because of implicit wait which I applied before starting my project...can we do something to start as in normal time interval.
– Samy
Mar 28 at 3:34
@Samy The condition to check if the list size is great than 0 does take some time when the element is not present on the page because it first finds the element on the whole page and then wait for the implicit wait as well and then it sends that the list size is equal to 0. However it would work real fast when the element is present on the page. So there is nothing that we can do about it, you can decrease your implicit wait if your other elements are not getting affected.
– Sameer Arora
Mar 28 at 3:38
@Samy The condition to check if the list size is great than 0 does take some time when the element is not present on the page because it first finds the element on the whole page and then wait for the implicit wait as well and then it sends that the list size is equal to 0. However it would work real fast when the element is present on the page. So there is nothing that we can do about it, you can decrease your implicit wait if your other elements are not getting affected.
– Sameer Arora
Mar 28 at 3:38
add a comment |
Replace the (clickHere.isDisplayed())
with below.
if(driver.findElements(By.xpath("//a[@href='/Account/Login']") ).size() != 0)
if you want to stick to your pagefactory then you can use the below approach
// below line will click on the "Click Here" link if only it's present
try clickHere.click();catch(Exception e)
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
if you would like to catch only NoSuchElementPresent
exception you can update to catch only that.
add a comment |
Replace the (clickHere.isDisplayed())
with below.
if(driver.findElements(By.xpath("//a[@href='/Account/Login']") ).size() != 0)
if you want to stick to your pagefactory then you can use the below approach
// below line will click on the "Click Here" link if only it's present
try clickHere.click();catch(Exception e)
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
if you would like to catch only NoSuchElementPresent
exception you can update to catch only that.
add a comment |
Replace the (clickHere.isDisplayed())
with below.
if(driver.findElements(By.xpath("//a[@href='/Account/Login']") ).size() != 0)
if you want to stick to your pagefactory then you can use the below approach
// below line will click on the "Click Here" link if only it's present
try clickHere.click();catch(Exception e)
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
if you would like to catch only NoSuchElementPresent
exception you can update to catch only that.
Replace the (clickHere.isDisplayed())
with below.
if(driver.findElements(By.xpath("//a[@href='/Account/Login']") ).size() != 0)
if you want to stick to your pagefactory then you can use the below approach
// below line will click on the "Click Here" link if only it's present
try clickHere.click();catch(Exception e)
username.sendKeys(strUsername);
nextBtn.click();
password.sendKeys(strPassword);
loginButton.click();
System.out.println("Successfully Logged");
if you would like to catch only NoSuchElementPresent
exception you can update to catch only that.
edited Mar 26 at 2:57
answered Mar 26 at 2:37
supputurisupputuri
5,1391 gold badge8 silver badges21 bronze badges
5,1391 gold badge8 silver badges21 bronze badges
add a comment |
add a comment |
You can create BaseClass for you PageObject and impelent metchod isElementOnPage
Base class:
public class BasePage
private WebDriver driver;
public BasePage(WebDriver driver)
this.driver = driver;
PageFactory.initElements(driver, this);
protected boolean isElementOnPage(WebElement webElement)
try
webElement.getTagName();
catch (Exception e)
return false;
return true;
Your Class:
public class PageClass extends BasePage
@FindBy(xpath="//a[@href='/Account/Login']")
private WebElement clickHere;
public PageClass(WebDriver driver)
super(driver);
public PageClass YourMethod()
if(isElementOnPage(clickHere))
clickHere.click();
// your logic here
else
// your logic here
return this;
add a comment |
You can create BaseClass for you PageObject and impelent metchod isElementOnPage
Base class:
public class BasePage
private WebDriver driver;
public BasePage(WebDriver driver)
this.driver = driver;
PageFactory.initElements(driver, this);
protected boolean isElementOnPage(WebElement webElement)
try
webElement.getTagName();
catch (Exception e)
return false;
return true;
Your Class:
public class PageClass extends BasePage
@FindBy(xpath="//a[@href='/Account/Login']")
private WebElement clickHere;
public PageClass(WebDriver driver)
super(driver);
public PageClass YourMethod()
if(isElementOnPage(clickHere))
clickHere.click();
// your logic here
else
// your logic here
return this;
add a comment |
You can create BaseClass for you PageObject and impelent metchod isElementOnPage
Base class:
public class BasePage
private WebDriver driver;
public BasePage(WebDriver driver)
this.driver = driver;
PageFactory.initElements(driver, this);
protected boolean isElementOnPage(WebElement webElement)
try
webElement.getTagName();
catch (Exception e)
return false;
return true;
Your Class:
public class PageClass extends BasePage
@FindBy(xpath="//a[@href='/Account/Login']")
private WebElement clickHere;
public PageClass(WebDriver driver)
super(driver);
public PageClass YourMethod()
if(isElementOnPage(clickHere))
clickHere.click();
// your logic here
else
// your logic here
return this;
You can create BaseClass for you PageObject and impelent metchod isElementOnPage
Base class:
public class BasePage
private WebDriver driver;
public BasePage(WebDriver driver)
this.driver = driver;
PageFactory.initElements(driver, this);
protected boolean isElementOnPage(WebElement webElement)
try
webElement.getTagName();
catch (Exception e)
return false;
return true;
Your Class:
public class PageClass extends BasePage
@FindBy(xpath="//a[@href='/Account/Login']")
private WebElement clickHere;
public PageClass(WebDriver driver)
super(driver);
public PageClass YourMethod()
if(isElementOnPage(clickHere))
clickHere.click();
// your logic here
else
// your logic here
return this;
edited Mar 26 at 22:28
Chris
1,2964 gold badges26 silver badges48 bronze badges
1,2964 gold badges26 silver badges48 bronze badges
answered Mar 26 at 20:35
Volodymyr RomanyshynVolodymyr Romanyshyn
11 bronze badge
11 bronze badge
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348059%2fhow-to-verify-specific-web-element-on-different-page-in-login-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown