无法使用 selenium webdriver 的 gettext() 从文本框中读取文本?

Unable to read text from textbox using gettext() of selenium webdriver?(无法使用 selenium webdriver 的 gettext() 从文本框中读取文本?)
本文介绍了无法使用 selenium webdriver 的 gettext() 从文本框中读取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

选择日期后,我无法从 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("//*[@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("//*[@id='ctl00_SampleContent_defaultCalendarExtender_day_"+i+"_"+j+"']")).getText()+"-");

            }
            System.out.println();
        }

        driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_defaultCalendarExtender_day_3_4']")).click();

        System.out.println(driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_Date1']")).getText());


        //Calendar with an associated button:

        System.out.println("Calendar with an associated button:------------------------------------------------------");

        driver.findElement(By.xpath("//*[@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("//*[@id='ctl00_SampleContent_calendarButtonExtender_day_"+i+"_"+j+"']")).getText()+"-");

            }
            System.out.println();
        }

        Thread.sleep(5000L);
        driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_Image1']")).click();
        driver.findElement(By.xpath("//*[@id='ctl00_SampleContent_calendarButtonExtender_day_3_3']")).click();

        System.out.println(driver.findElement(By.xpath("//*[@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() 从文本框中读取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)
WebKit quot;Refused to set unsafe header #39;content-length#39;quot;(WebKit “拒绝设置不安全的标头‘内容长度’)
$.ajax call working fine in IE8 and Doesn#39;t work in firefox and chrome browsers($.ajax 调用在 IE8 中运行良好,但在 Firefox 和 chrome 浏览器中不起作用)
How do I know if jQuery has an Ajax request pending?(我如何知道 jQuery 是否有待处理的 Ajax 请求?)