Java Selenium Click a certain button on a certain day
![Multi tool use Multi tool use](http://sgv.ssvwv.com/sg/ssvwvcomimagb.png)
Multi tool use
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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
add a comment |
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
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
add a comment |
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
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
java selenium automation selenium-chromedriver
edited Jan 3 at 22:37
![](https://i.stack.imgur.com/7tddL.jpg?s=32&g=1)
![](https://i.stack.imgur.com/7tddL.jpg?s=32&g=1)
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
One more thing. RemoveThread.sleep(5000);
which is located inselectCorrectWeekday()
. Replace it with more relevant code, which for example verify some state.
– Zhivko.Kostadinov
Jan 4 at 13:45
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%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
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.
One more thing. RemoveThread.sleep(5000);
which is located inselectCorrectWeekday()
. Replace it with more relevant code, which for example verify some state.
– Zhivko.Kostadinov
Jan 4 at 13:45
add a comment |
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.
One more thing. RemoveThread.sleep(5000);
which is located inselectCorrectWeekday()
. Replace it with more relevant code, which for example verify some state.
– Zhivko.Kostadinov
Jan 4 at 13:45
add a comment |
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.
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.
answered Jan 4 at 7:49
pburgrpburgr
4771210
4771210
One more thing. RemoveThread.sleep(5000);
which is located inselectCorrectWeekday()
. Replace it with more relevant code, which for example verify some state.
– Zhivko.Kostadinov
Jan 4 at 13:45
add a comment |
One more thing. RemoveThread.sleep(5000);
which is located inselectCorrectWeekday()
. 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
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%2f54030503%2fjava-selenium-click-a-certain-button-on-a-certain-day%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
E6z6,kj m CmmfjvABPEi uA1annrZ h1vwTM McmCujJk6URJyh
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