0

从 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'
4

1 回答 1

1

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

于 2021-03-15T15:22:58.430 回答