class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome() #opens chrome to complete the task
def test_search_in_python_org(self):
driver = self.driver
driver.get(URL) #uses the URL that was generated at the start of the task
self.assertIn("adidas", driver.title)
elem = driver.find_element_by_name("Add to Bag") #finds the 'add to bag' button (for adidas.com) and clicks it
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
selenium.click("Add to Bag")
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
現在我正在試驗python並試圖爲adidas.com製作一個簡單的機器人,它將產品添加到購物車中。我使用硒來做到這一點。我努力硒點擊「添加到購物籃」按鈕,但是當我跑我得到這個錯誤:Python硒:無法定位網頁上的元素
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"Add to Bag"}
它不能在網站上找到了「添加到購物籃」按鈕,即使我知道它的存在。我究竟做錯了什麼?
在此先感謝
您可以添加網站的網址 – Hackerman
是的,這裏是我的代碼的頂部:高清UrlGen(型號,尺寸): BaseSize = 550 #size 5,上升10各佔一半大小 ShoeSize =大小 - 5 ShoeSize = ShoeSize * 20 RawSize = ShoeSize + BaseSize ShoeSizeCode = int(RawSize) URL ='http://www.adidas.com/us/'+ str(model)+'.html?forceSelSize ='+ str(模型)+ '_' + STR(ShoeSizeCode) 返回URL 模型=的raw_input( '型號') 尺寸=輸入( '尺寸:') URL = UrlGen(型號,尺寸) 打印(STR( URL) ) – cgreene