簡體   English   中英

Selenium + Python:將文本存儲在變量中並打印

[英]Selenium + Python: Store text in a variable and print

我正在嘗試使用send_keys填充字段,同時將此值存儲在變量中。 當我運行此代碼時,不會打印變量的文本。

locators.py

from selenium.webdriver.common.by import By

class CreateNewContractor(object):

  FIRST_NAME = (By.ID, "id_0-first_name")

pages.py

from locators import *

class CreateNewContractor1(Page):


    def fill_contractor(self):

        email = self.find_element(*CreateNewContractor.FIRST_NAME).send_keys("Hello")
        email.text
        print email

如何存儲和打印電子郵件變量中填充的文本?

email變量將獲得價值None -這就是send_keys()方法返回。

相反,您可以簡單地將文本保留在變量中:

text = "hello"
self.find_element(*CreateNewContractor.FIRST_NAME).send_keys(text)
print(text)

或者,如果您想實際獲得input的值,請使用get_attribute()方法:

elm = self.find_element(*CreateNewContractor.FIRST_NAME)
elm.send_keys("hello")
print(elm.get_attribute("value"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM