这是Chrome的代码片段:
driver.get("https://www.youtube.com/")
driver.find_element_by_xpath('//*[@id="search"]').send_keys("kao")
driver.find_element_by_xpath('//*[@id="search-icon-legacy"]').click()
浏览器会自动打开YouTube和搜索所传递的字符串[这是我打算做任务]
当我开始使用properly.I我基本上使用相同的代码,但我每次运行时firefox.The加载页面出现的主要问题,它引发以下错误:
Message: Element <g id="search"> is not reachable
我不能任何字符串传递到搜索栏,甚至点击它。
您的XPath是不正确的。这是无法找到搜索栏和按钮
您可以使用此一个
driver.get("https://www.youtube.com/")
driver.find_element_by_xpath("//input[@id='search']").send_keys("kao")
driver.find_element_by_xpath("//button[@id='search-icon-legacy']").click()