本文介紹了無法使用 selenium webdriver 的 gettext() 從文本框中讀取文本?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
選擇日期后,我無法從 ajax 日歷控件中讀取日期
I can't read dates from ajax calendar control after date selection
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/日歷.aspx
我沒有收到任何錯誤,但我無法從文本框中獲取任何值.
I don't get any error but I can't fetch any value from textbox.
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx");
driver.manage().window().maximize();
//Default calendar:
driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_Date1']")).click();
for(int i=0;i<=5;i++){
for(int j = 0;j<=6;j++){
System.out.print(driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_defaultCalendarExtender_day_"+i+"_"+j+"']")).getText()+"-");
}
System.out.println();
}
driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_defaultCalendarExtender_day_3_4']")).click();
System.out.println(driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_Date1']")).getText());
//Calendar with an associated button:
System.out.println("Calendar with an associated button:------------------------------------------------------");
driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_Image1']")).click();
for(int i=0;i<=5;i++){
for(int j = 0;j<=6;j++){
System.out.print(driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_calendarButtonExtender_day_"+i+"_"+j+"']")).getText()+"-");
}
System.out.println();
}
Thread.sleep(5000L);
driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_Image1']")).click();
driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_calendarButtonExtender_day_3_3']")).click();
System.out.println(driver.findElement(By.xpath("http://*[@id='ctl00_SampleContent_Date5']")).getText());
}
推薦答案
獲取 input
文本的調用應該是:
The call to get the input
text should be:
driver.findElement(By.id("ctl00_SampleContent_Date5")).getAttribute("value");
別問我為什么,就是這樣一直是.通過鍵入 input
元素,您正在更改其 value
屬性.
Don't ask me why, it's just the way it always has been. By typing into an input
element, you are changing its value
attribute.
這篇關于無法使用 selenium webdriver 的 gettext() 從文本框中讀取文本?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!