[英]How to select date , Month , and year from a calendar using selenium with Python
How to select date, Month and year from a calendar using selenium with Python without Hardcoding如何使用 selenium 和 Python 从日历中获取 select 日期、月份和年份,而无需硬编码
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class fbcalender {
static WebDriver driver;
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Downloads\\chromedriver83\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
//Here you can give dates as parameters
setday(driver,"12","Aug","1999");
}
public static void setday(WebDriver driver,String day,String month,String year)
{
// Select date
Select dates=new Select(driver.findElement(By.id("day")));
dates.selectByValue(day);
//select month from drop down
Select Months=new Select(driver.findElement(By.id("month")));
Months.selectByVisibleText(month);
//select year
Select Years=new Select(driver.findElement(By.id("year")));
Years.selectByVisibleText(year);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.