如何获取日历值

时间:2018-02-21 11:29:55

标签: python selenium selenium-webdriver calendar

我想要来自 html脚本的值,我正在尝试使用print在我的屏幕上打印它但是它无法正常使用python 2.7和selenium进行自动化测试我怎样才能获得日历值得感谢。working on this website

import unittest
import time
import gettext
import HtmlTestRunner
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.action_chains import ActionChains

class xyz(unittest.TestCase):
    def setUp(self):

        self.driver=webdriver.Chrome()
        driver=self.driver



    def test_xy_org(self):
        self.driver.get("https://www.veenaworld.com/")
        self.driver.maximize_window()
        find=self.driver.find_element_by_xpath("//input[@id='txtSearch']")
        find.send_keys("pune")
        find.send_keys(Keys.RETURN)
        find2=self.driver.find_element_by_xpath("//input[@onblur]") 
        find2.send_keys("pune")
        find2.send_keys(Keys.RETUR)
        self.driver.get("https://www.veenaworld.com/Package/Detail?pCode=RJZB(IP)&cCode=2")
        enquiry=self.driver.find_element_by_xpath("//a[text()='Enquiry']").click()
        name=self.driver.find_element_by_xpath("//input[@id='txtEnName']")
        name.send_keys("prajkta")
        phn=self.driver.find_element_by_xpath("//input[@id='txtEnContact']")
        phn.send_keys("4569874556")
        city=self.driver.find_element_by_xpath("//select[@id='ddlEnCountry']").click()
        city1=self.driver.find_element_by_xpath("id('ddlEnCountry')/option[6]").click()
        email=self.driver.find_element_by_xpath("//input[@id='txtEnEmail']")
        email.send_keys("fgdshk@gmail.com")
        destination=self.driver.find_element_by_xpath("id('ddlEnDest')/optgroup[2]/option[4]").click()
        travel=self.driver.find_element_by_xpath("id('optTour')/option[2]").click()
        mounth=self.driver.find_element_by_xpath("id('ddlEnTMonth')/option[7]").click()
        year=self.driver.find_element_by_xpath("id('ddlEnTYear')/option[3]").click()
        more=self.driver.find_element_by_xpath("id('txtEnMoreDetail')")
        more.send_keys("djgfjhgdh genghruu jjdhgjh gerhjhrj")
        option=self.driver.find_element_by_xpath("id('EmailMe1')").click()
        submit=self.driver.find_element_by_xpath("id('frmEnquiry')/div[1]/div[12]/input[1]").click()
        time.sleep(5)

        self.driver.get("https://www.veenaworld.com/")
        flights=self.driver.find_element_by_xpath("//a[@href='#hm_tab2']").click()
        from1=self.driver.find_element_by_xpath("//input[@id='fromcityAc']")
        from1.send_keys("pune")
        to=self.driver.find_element_by_xpath("//input[@id='tocityAc']")
        to.send_keys("mumbai")
        travellers = self.driver.find_element_by_xpath( "//div[@id='Travellersection']//div[@class='dd_poup']//p[@class='dd_poplink']//span[@class='dd_poplink_span']").click()
        option = self.driver.find_element_by_xpath("//select[@id='ddlAdultInt']").click()
        adult = self.driver.find_element_by_xpath("//select[@id='ddlAdultInt']//option[@vlaue='2']").click()
        option1 = self.driver.find_element_by_xpath("//select[@id='ddlAdultInt']//option[@vlaue='2']").click()
        self.ab()


    def ab(self):
        date=self.driver.find_element_by_xpath("//input[@id='txtFlightDepartureDate']").click()
        month=self.driver.find_element_by_xpath("/html[1]/body[1]/div[2]/div[1]/div[2]/div[1]/div[1]") 
        to_month_string = month.get_attribute('value')
        print 'to_month_string'
        date='Feb 2018'
        if to_month_string==date:
         print "month selected"
        else: 
         for x in to_month_string:
               click1=self.driver.find_element_by_xpath("//html//div[@class='datepick-popup']//a[3]").click()



if __name__=="__main__":

     unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='example17_dir'))

请参阅

第二功能def ab(自我):

date =我试图点击日历

之后我会给出 xpath 的月份,找到日历月份以及我要打印的内容作为输出

2 个答案:

答案 0 :(得分:1)

以下代码是针对日历的,具有轮式视图&从第一个轮子我们可以通过旋转该轮子来选择日期。选择月份和时间相同最后有确认按钮来保存日期。

    public void verifyClickOnDate() {
                IOSElement Date = driver.findElement(By.xpath(Xpaths.DATE));
                Date.click();
                driver.findElementByXPath(("//XCUIElementTypeDatePicker/XCUIElementTypeOther/XCUIElementTypePickerWheel[1]")).sendKeys("28");
                driver.findElementByXPath(("//XCUIElementTypeDatePicker/XCUIElementTypeOther/XCUIElementTypePickerWheel[2]")).sendKeys("December");       
                driver.findElementByXPath(("//XCUIElementTypeDatePicker/XCUIElementTypeOther/XCUIElementTypePickerWheel[3]")).sendKeys("2018");
                IOSElement confirmDate = driver.findElement(By.xpath(Xpaths.CONFIRM_DATE_BUTTON));
                confirmDate.click();
                String Date = driver.findElement(By.xpath(Xpaths.DATE)).getText();

            }  

答案 1 :(得分:0)

您可以尝试从给定标记中获取文本值。

尝试以下代码行

month=self.driver.find_element_by_xpath("/html[1]/body[1]/div[2]/div[1]/div[2]/div[1]/div[1]") 
        to_month_string = month.text;