Python Selenium打印出的textfield值显示为空。(Python Selenium print out value of textfield is showing empty. Th

编程入门 行业动态 更新时间:2024-10-12 05:47:53
Python Selenium打印出的textfield值显示为空。(Python Selenium print out value of textfield is showing empty. The value is not printing)

我试图将文本字段的值打印到控制台。 网页在文本字段中的值为1,000.000。 应该打印1,000.000,但我的方法是打印空白。 我正在使用Python Webdriver。 我正在使用.text,它应该获取文本字段的文本值。

我的方法是:

from selenium.webdriver.common.by import By # max records textfield has the value 1,000.000 as default def print_maxrecords_textfield(self): max_records_textfield = self.driver.find_element((By.XPATH, '//span[@class="gwt-InlineLabel myinlineblock marginbelow" and contains(text(), "Max records")]/following-sibling::*')) print "max_records_textfield = " print max_records_textfield.text

我将测试用例类中的方法称为dp.print_maxrecords_textfield()

控制台的输出如下:

max_records_textfield =

应该说max_records_textfield = 1,000.00

HTML代码段是:

<div class="padding gwt-TabLayoutPanelContent" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;" aria-hidden="false"> <div class="clear"> <span class="gwt-InlineLabel marginbelow myinlineblock" style="width: 8em;">Location</span> <input class="gwt-TextBox marginbelow" type="text" style="width: 30em;"/> </div> <div class="clear"> <span class="gwt-InlineLabel myinlineblock marginbelow" style="width: 8em;">Max records</span> <input class="gwt-IntegerBox marginbelow" type="text"/> </div>

I am trying to print out the value of a textfield to the console. The webpage has the value 1,000.000 in the textfield. 1,000.000 should be printed but my method is printing blank. I am using Python Webdriver. I am using the .text which should get the text value of the textfield.

My method is:

from selenium.webdriver.common.by import By # max records textfield has the value 1,000.000 as default def print_maxrecords_textfield(self): max_records_textfield = self.driver.find_element((By.XPATH, '//span[@class="gwt-InlineLabel myinlineblock marginbelow" and contains(text(), "Max records")]/following-sibling::*')) print "max_records_textfield = " print max_records_textfield.text

I call the method from my test case class as dp.print_maxrecords_textfield()

The output to the console is as follows:

max_records_textfield =

It should say max_records_textfield = 1,000.00

The HTML snippet is:

<div class="padding gwt-TabLayoutPanelContent" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;" aria-hidden="false"> <div class="clear"> <span class="gwt-InlineLabel marginbelow myinlineblock" style="width: 8em;">Location</span> <input class="gwt-TextBox marginbelow" type="text" style="width: 30em;"/> </div> <div class="clear"> <span class="gwt-InlineLabel myinlineblock marginbelow" style="width: 8em;">Max records</span> <input class="gwt-IntegerBox marginbelow" type="text"/> </div>

最满意答案

实际上尝试获取值而不是文本。

from selenium.webdriver.common.by import By # max records textfield has the value 1,000.000 as default def print_maxrecords_textfield(self): max_records_textfield = self.driver.find_element((By.XPATH, '//span[@class="gwt-InlineLabel myinlineblock marginbelow" and contains(text(), "Max records")]/following-sibling::*')) print "max_records_textfield = " print max_records_textfield.get_attribute('value')

Actually try getting the value instead of text.

from selenium.webdriver.common.by import By # max records textfield has the value 1,000.000 as default def print_maxrecords_textfield(self): max_records_textfield = self.driver.find_element((By.XPATH, '//span[@class="gwt-InlineLabel myinlineblock marginbelow" and contains(text(), "Max records")]/following-sibling::*')) print "max_records_textfield = " print max_records_textfield.get_attribute('value')

更多推荐

本文发布于:2023-08-06 21:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456347.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   textfield   Selenium   Python   printing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!