Java Selenium Click a certain button on a certain day





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















So I'm having an issue with clicking a button on a certain day. The website I'm scripting for has couple of options. Week, Month and Year. When you press Week you get the option to select the day of the week. Monday, Tuesday and so on. When you press Month, you get the same thing for months.



My issue is how do I automate it so when I need to select the day of the week it checks the date and selects the correct date.



I have no issue with checking the date or clicking a button I just don't know how to combine the two.










share|improve this question




















  • 2





    Hi. Welcome to SO. Chow us some of your code so it will be easier for us to help you.

    – Ludovit Mydla
    Jan 3 at 22:28


















0















So I'm having an issue with clicking a button on a certain day. The website I'm scripting for has couple of options. Week, Month and Year. When you press Week you get the option to select the day of the week. Monday, Tuesday and so on. When you press Month, you get the same thing for months.



My issue is how do I automate it so when I need to select the day of the week it checks the date and selects the correct date.



I have no issue with checking the date or clicking a button I just don't know how to combine the two.










share|improve this question




















  • 2





    Hi. Welcome to SO. Chow us some of your code so it will be easier for us to help you.

    – Ludovit Mydla
    Jan 3 at 22:28














0












0








0








So I'm having an issue with clicking a button on a certain day. The website I'm scripting for has couple of options. Week, Month and Year. When you press Week you get the option to select the day of the week. Monday, Tuesday and so on. When you press Month, you get the same thing for months.



My issue is how do I automate it so when I need to select the day of the week it checks the date and selects the correct date.



I have no issue with checking the date or clicking a button I just don't know how to combine the two.










share|improve this question
















So I'm having an issue with clicking a button on a certain day. The website I'm scripting for has couple of options. Week, Month and Year. When you press Week you get the option to select the day of the week. Monday, Tuesday and so on. When you press Month, you get the same thing for months.



My issue is how do I automate it so when I need to select the day of the week it checks the date and selects the correct date.



I have no issue with checking the date or clicking a button I just don't know how to combine the two.







java selenium automation selenium-chromedriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 22:37









Brian

4,65972943




4,65972943










asked Jan 3 at 22:12









ArchesikArchesik

1




1








  • 2





    Hi. Welcome to SO. Chow us some of your code so it will be easier for us to help you.

    – Ludovit Mydla
    Jan 3 at 22:28














  • 2





    Hi. Welcome to SO. Chow us some of your code so it will be easier for us to help you.

    – Ludovit Mydla
    Jan 3 at 22:28








2




2





Hi. Welcome to SO. Chow us some of your code so it will be easier for us to help you.

– Ludovit Mydla
Jan 3 at 22:28





Hi. Welcome to SO. Chow us some of your code so it will be easier for us to help you.

– Ludovit Mydla
Jan 3 at 22:28












1 Answer
1






active

oldest

votes


















0














You have to be able to get a match between current weekday and one the seven webelements. An example of selecting weekday on the web https://www.phpro.org/examples/Days-Of-Week-Dropdown.html:



public void selectCorrectWeekday() throws InterruptedException {

String weekDayCapitalized = weekDay().substring(0, 1).toUpperCase() + weekDay().substring(1);
driver.get("https://www.phpro.org/examples/Days-Of-Week-Dropdown.html");
new Select(waitSec(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("day")))).selectByVisibleText(weekDayCapitalized);
Thread.sleep(5000);

}

public WebDriverWait waitSec(WebDriver driver, int sec) {return new WebDriverWait(driver, sec);}
public String weekDay() {return today().getDayOfWeek().name().toString().toLowerCase();}
public LocalDate today() {LocalDate today = LocalDate.now();return today;}


However your approach will be different due to html source code.






share|improve this answer
























  • One more thing. Remove Thread.sleep(5000); which is located in selectCorrectWeekday(). Replace it with more relevant code, which for example verify some state.

    – Zhivko.Kostadinov
    Jan 4 at 13:45














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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030503%2fjava-selenium-click-a-certain-button-on-a-certain-day%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You have to be able to get a match between current weekday and one the seven webelements. An example of selecting weekday on the web https://www.phpro.org/examples/Days-Of-Week-Dropdown.html:



public void selectCorrectWeekday() throws InterruptedException {

String weekDayCapitalized = weekDay().substring(0, 1).toUpperCase() + weekDay().substring(1);
driver.get("https://www.phpro.org/examples/Days-Of-Week-Dropdown.html");
new Select(waitSec(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("day")))).selectByVisibleText(weekDayCapitalized);
Thread.sleep(5000);

}

public WebDriverWait waitSec(WebDriver driver, int sec) {return new WebDriverWait(driver, sec);}
public String weekDay() {return today().getDayOfWeek().name().toString().toLowerCase();}
public LocalDate today() {LocalDate today = LocalDate.now();return today;}


However your approach will be different due to html source code.






share|improve this answer
























  • One more thing. Remove Thread.sleep(5000); which is located in selectCorrectWeekday(). Replace it with more relevant code, which for example verify some state.

    – Zhivko.Kostadinov
    Jan 4 at 13:45


















0














You have to be able to get a match between current weekday and one the seven webelements. An example of selecting weekday on the web https://www.phpro.org/examples/Days-Of-Week-Dropdown.html:



public void selectCorrectWeekday() throws InterruptedException {

String weekDayCapitalized = weekDay().substring(0, 1).toUpperCase() + weekDay().substring(1);
driver.get("https://www.phpro.org/examples/Days-Of-Week-Dropdown.html");
new Select(waitSec(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("day")))).selectByVisibleText(weekDayCapitalized);
Thread.sleep(5000);

}

public WebDriverWait waitSec(WebDriver driver, int sec) {return new WebDriverWait(driver, sec);}
public String weekDay() {return today().getDayOfWeek().name().toString().toLowerCase();}
public LocalDate today() {LocalDate today = LocalDate.now();return today;}


However your approach will be different due to html source code.






share|improve this answer
























  • One more thing. Remove Thread.sleep(5000); which is located in selectCorrectWeekday(). Replace it with more relevant code, which for example verify some state.

    – Zhivko.Kostadinov
    Jan 4 at 13:45
















0












0








0







You have to be able to get a match between current weekday and one the seven webelements. An example of selecting weekday on the web https://www.phpro.org/examples/Days-Of-Week-Dropdown.html:



public void selectCorrectWeekday() throws InterruptedException {

String weekDayCapitalized = weekDay().substring(0, 1).toUpperCase() + weekDay().substring(1);
driver.get("https://www.phpro.org/examples/Days-Of-Week-Dropdown.html");
new Select(waitSec(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("day")))).selectByVisibleText(weekDayCapitalized);
Thread.sleep(5000);

}

public WebDriverWait waitSec(WebDriver driver, int sec) {return new WebDriverWait(driver, sec);}
public String weekDay() {return today().getDayOfWeek().name().toString().toLowerCase();}
public LocalDate today() {LocalDate today = LocalDate.now();return today;}


However your approach will be different due to html source code.






share|improve this answer













You have to be able to get a match between current weekday and one the seven webelements. An example of selecting weekday on the web https://www.phpro.org/examples/Days-Of-Week-Dropdown.html:



public void selectCorrectWeekday() throws InterruptedException {

String weekDayCapitalized = weekDay().substring(0, 1).toUpperCase() + weekDay().substring(1);
driver.get("https://www.phpro.org/examples/Days-Of-Week-Dropdown.html");
new Select(waitSec(driver, 10).until(ExpectedConditions.elementToBeClickable(By.id("day")))).selectByVisibleText(weekDayCapitalized);
Thread.sleep(5000);

}

public WebDriverWait waitSec(WebDriver driver, int sec) {return new WebDriverWait(driver, sec);}
public String weekDay() {return today().getDayOfWeek().name().toString().toLowerCase();}
public LocalDate today() {LocalDate today = LocalDate.now();return today;}


However your approach will be different due to html source code.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 4 at 7:49









pburgrpburgr

4771210




4771210













  • One more thing. Remove Thread.sleep(5000); which is located in selectCorrectWeekday(). Replace it with more relevant code, which for example verify some state.

    – Zhivko.Kostadinov
    Jan 4 at 13:45





















  • One more thing. Remove Thread.sleep(5000); which is located in selectCorrectWeekday(). Replace it with more relevant code, which for example verify some state.

    – Zhivko.Kostadinov
    Jan 4 at 13:45



















One more thing. Remove Thread.sleep(5000); which is located in selectCorrectWeekday(). Replace it with more relevant code, which for example verify some state.

– Zhivko.Kostadinov
Jan 4 at 13:45







One more thing. Remove Thread.sleep(5000); which is located in selectCorrectWeekday(). Replace it with more relevant code, which for example verify some state.

– Zhivko.Kostadinov
Jan 4 at 13:45






















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030503%2fjava-selenium-click-a-certain-button-on-a-certain-day%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Angular Downloading a file using contenturl with Basic Authentication

Monofisismo

Olmecas