【问题标题】:AttributeError: 'tuple' object has no attribute 'tag_name'AttributeError: 'tuple' 对象没有属性 'tag_name'
【发布时间】:2021-03-18 18:46:34
【问题描述】:

从 Selenium 中具有选择标签的下拉列表中选择值。但是,从下拉列表中选择值时出现以下错误。

她是我的代码:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.select import Select
    import time
    from Pages.BasePage import Common
    from configration.config import Data
    
    
    class OrderCycle(Common):
        # By Locator
        
        US_State = (By.XPATH, "//option[@value='AL']")
       
    
        # Constructor of the page class
    
        def __init__(self, driver):
            # super().__init__(driver)
            self.driver = driver
            self.driver.get(Data.Base_url)
        # Page Action for Order cycle
    
      
        # Select the state from the Dropdown.
        def select_state(self):
            self.do_click(self.US_State), Select(self.US_State).select_by_visible_text("Alabama")

实际结果:

FAILED Test/test_CartItem.py::TestOrder::test_select_product[chrome] - AttributeError: 'tuple' object has no attribute 'tag_name'
FAILED Test/test_CartItem.py::TestOrder::test_select_product[firefox] - AttributeError: 'tuple' object has no attribute 'tag_name'

【问题讨论】:

  • Common 使用的是哪个库?
  • Maximilian Peters:这不是一个库,这是我在 OrderCylce 类中继承的类名。下面是代码: 类 Common: def __int__(self, driver): self.driver = driver def do_click(self, by_locator): WebDriverWait(self.driver, 30).until(EC.visibility_of_element_located(by_locator)).click( ) def do_send_keys(self, by_locator, text): WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(by_locator)).send_keys(text)
  • 您的代码不包含失败的测试。请考虑提供一个minimal reproducible example 来重现错误。很可能在 return 语句的某处放置了一个不必要的逗号。
  • 您可以将所有代码添加到您的问题中吗?

标签: python selenium pycharm pytest python-3.9


【解决方案1】:

卸下支架,它现在可以工作了。 US_State = By.XPATH, "//option[@value='AL']"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-26
    • 2018-10-19
    • 2015-06-22
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    相关资源
    最近更新 更多