硒上的AttributeError:'NoneType' [英] AttributeError: 'NoneType' on selenium

查看:53
本文介绍了硒上的AttributeError:'NoneType'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码有错误,我想获取或打印产品文本,但是当我运行它时,它给了我一个错误.

I have a error in my code, I want to get or to print the product text but when i run it it gave me an error.

这是我的代码:

import kivy
from kivy.properties import ObjectProperty
from selenium import webdriver
import requests
from selectorlib import Extractor
from selenium.webdriver.common.keys import Keys
from kivymd.app import MDApp
from kivy.app import App
from kivy.lang import Builder

KV = '''
BoxLayout:
    product: product
    size_hint: .8, .8
    pos_hint: {"center_x": .5, "center_y": .5}
    spacing: dp(100)
    orientation: "vertical"
    MDTextFieldRound:
        id: product
        hint_text: 'Enter a product'
        icon_left: 'magnify'
        on_text_validate: app.System()

'''


class Main(MDApp):
    def build(self):
        return Builder.load_string(KV)

    product = ObjectProperty(None)

    def System(self):
        print(self.product.text)


if __name__ == "__main__":
    Main().run() 

它总是给我下一个错误

   File "C:/Users/Yesnia/Desktop/PYTHON/Apps development/App/App_Checking_Store.py", line 34, in 
   System
   print(self.product.text)
   AttributeError: 'NoneType' object has no attribute 'text'

请帮助我

推荐答案

因此,您构建了kv字符串,但是无法引用它.有很多方法可以解决这种情况,下面是一个示例.

So you build your kv string but have no way to reference it. There are many ways to mend the situation, heres an example.

KV = '''
BoxLayout:
    ###product: product ### this does not achieve anything, you're just giving
    #some generic box layout a product attribute. this does not assign the App attribute.
    size_hint: .8, .8
    pos_hint: {"center_x": .5, "center_y": .5}
    spacing: dp(100)
    orientation: "vertical"
    MDTextFieldRound:
        id: product
        hint_text: 'Enter a product'
        icon_left: 'magnify'
        on_text_validate: app.System()

'''


class Main(MDApp):
    product = ObjectProperty(None)
    my_kv = None
    def build(self):
        self.my_kv = Builder.load_string(KV)
        self.product = self.my_kv.ids.product
        return self.my_kv

    def System(self):
        print(self.product.text)

请注意我在您的kv字符串中留下的注释,为您的App类添加了新的my_kv属性,以及我对构建函数所做的更改.

notice the comment i've left in your kv string, the addition of the new my_kv attribute to your App class, and the changes I've made to your build function.

希望这会有所帮助!

这篇关于硒上的AttributeError:'NoneType'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆