Selenium Webdriver CSS Selector Help - for Selecting Date

How select date in calendar with Selenium?

Your question is a bit hard to understand and based on my understanding, can you please try this?

ClickElementByCssSelector("td[class='day selected today']");

How to find element by css selector for date field in Python selenium?

Induce WebDriverWait and following Css Selector.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input.hasDatepicker[desc='Start Date']")))
element.click()

EDITED

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
for i in range(0,3):
element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input.hasDatepicker[desc='Start Date']")))
element.click()

OR

element=WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input.hasDatepicker[desc='Start Date']")))
driver.execute_script("arguments[0].click();",element)
driver.execute_script("arguments[0].click();",element)
driver.execute_script("arguments[0].click();",element)

Using Selenium to automatically select a date in a datepicker

It looks like you can select it by its class:

WebDriver.FindElement(By.CssSelector(".dpTD")).Click();

Or if there's more than one cell with that class, try narrowing it down with :contains():

WebDriver.FindElement(By.CssSelector(".dpTD:contains('3')")).Click();

Or even an attribute substring selector:

WebDriver.FindElement(By.CssSelector(".dpTD[onclick*=updateDateField]")).Click();

I'm just throwing suggestions out here as there's not enough markup to work with. If you've worked with CSS, you can use almost any selector with Selenium.

Select date from daterangepicker using selenium

I've got a brute-force solution:

from selenium.webdriver.common.action_chains import ActionChains as AC

element = driver.find_element_by_xpath('//td[contains(text(), "9") and contains(@class, "available")]')

AC.move_to_element_with_offset(element, 35, 30).click().perform()

So basically it finds the calendar day '9' and moves 35 pixels right and 30 pixels down, where '17' should be, and clicks there. Obviously this setup will be different for different months. It's a primitive solution but hey, it might just work.

Can't seem to select Date range picker by it's XPATH using selenium

The date picker element is present inside an iframe.You need to switch the iframe first to access the date picker.

Induce WebDriverWait() and wait for frame_to_be_available_and_switch_to_it() and use following css selector.

Then you can click on date picker using following xpath.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("http://covid.gov.pk/stats/pakistan")
#wait for Page to load
WebDriverWait(driver,30).until(EC.invisibility_of_element((By.XPATH, "//div[@id='preloader']")))
WebDriverWait(driver,20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,".pak-stats-ifrm")))
#select date range picker
element = driver.find_element_by_xpath("//div[@class='content-holder ng-scope']")
element.click()

How to select the Date Picker In Selenium WebDriver

DatePicker are not Select element. What your doing in your code is wrong.

Datepicker are in fact table with set of rows and columns.To select a date you just have to navigate to the cell where our desired date is present.

So your code should be like this:

WebElement dateWidget = driver.findElement(your locator);
List<WebElement> columns=dateWidget.findElements(By.tagName("td"));

for (WebElement cell: columns){
//Select 13th Date
if (cell.getText().equals("13")){
cell.findElement(By.linkText("13")).click();
break;
}

Jmeter´s WebDriver Sampler - CSS Locator Wildcard

I don't think CSS Selectors support wildcards in the attributes names

The easiest option is calculating the current week number beforehand and use string concatenation to insert it into the CSS expression, something like:

var currentWeek = Math.floor(new Date().getDate() / 7) + 1
WDS.browser.findElement(pkg.By.cssSelector("#_z_0-w" + currentWeek > td.z-calendar-cell.z-calendar-weekday.z-calendar-selected")).click()

More information on the WebDriver Sampler: The WebDriver Sampler: Your Top 10 Questions Answered



Related Topics



Leave a reply



Submit