无法使用selenium登录
我正在尝试自动登录到这个 登录菜单位于网站的右上角 我已经尝试通过CSS选择器、Xpath、名称和此操作来查找登录表单 编辑1:我还尝试将鼠标悬停在带有actionchains的登录上,然后按元素查找。未找到任何元素,也未发送任何密钥 结果:无法使用selenium登录,selenium,automation,Selenium,Automation,我正在尝试自动登录到这个 登录菜单位于网站的右上角 我已经尝试通过CSS选择器、Xpath、名称和此操作来查找登录表单 编辑1:我还尝试将鼠标悬停在带有actionchains的登录上,然后按元素查找。未找到任何元素,也未发送任何密钥 结果: wd.get("http://www.vatgia.com") action = ActionChains(wd); action.move_to_element(wd.find_element_by_css_selector("#header_bar
wd.get("http://www.vatgia.com")
action = ActionChains(wd);
action.move_to_element(wd.find_element_by_css_selector("#header_bar > div > div.fr > a:nth-child(8)"))
action.send_keys("loginsampling")
action.perform();
通过CSS
,Xpath
查找,名称显示:元素不可见;
操作事件:我将鼠标悬停在登录区域上,发送键,登录区域弹出,但没有发送键,没有显示错误
动作事件的我的代码:
wd.get("http://www.vatgia.com")
action = ActionChains(wd);
action.move_to_element(wd.find_element_by_css_selector("#header_bar > div > div.fr > a:nth-child(8)"))
action.send_keys("loginsampling")
action.perform();
p/s:感谢布莱恩的编辑
最终更新:
wd.get("http://www.vatgia.com")
action = ActionChains(wd);
action.move_to_element(wd.find_element_by_css_selector("#header_bar > div > div.fr > a:nth-child(8)"))
action.send_keys("loginsampling")
action.perform();
Mahipal为我提供了解决方案。我应该使用xpath作为登录表单和密码的容器。我以前只右键单击并复制xpath元素,但这不起作用。谢谢Mahipal 这是因为在尝试查找登录按钮之前,您没有打开登录下拉列表。您需要找到下拉元素,单击它,然后找到登录字段和按钮并执行操作。您可以使用登录菜单的容器来标识其字段,如下所示:
driver.findElement(By.xpath("//div[@id='header_bar']//a[@rel='#header_login']")).click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOf(
driver.findElement(By.xpath("//div[@id='simple_tip']//div/input[@name='loginname']"))));
driver.findElement(By.xpath("//div[@id='simple_tip']//div/input[@name='loginname']")).sendKeys("login_name");
试试上面的代码,让我知道它是否适合您。我找到了,我找到了下拉列表的元素。在findby元素中,我单击它并尝试查找登录表单。在动作中,我将鼠标悬停在它上面,然后尝试发送钥匙。不客气,基恩:)哦,我的布达,它起作用了:D非常感谢你,我需要更深入地了解这一点。谢谢你Mahipal!!!