Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用Selenium和Python在弹出窗口中登录_Python 3.x_Selenium Webdriver - Fatal编程技术网

Python 3.x 使用Selenium和Python在弹出窗口中登录

Python 3.x 使用Selenium和Python在弹出窗口中登录,python-3.x,selenium-webdriver,Python 3.x,Selenium Webdriver,我正在尝试使用Python 3中的selenium webdriver登录到一个服务器上。首先,我需要单击按钮“Inloggen”,然后我需要填写用户名和密码,然后再次单击(新建)按钮“Inloggen” 因此,我尝试定位第一个“Inloggen”按钮(使用下面的代码),并尝试单击它,但随后它会引发错误“selenium.common.exceptions.WebDriverException:Message:”,但没有消息 from selenium import webdriver # g

我正在尝试使用Python 3中的selenium webdriver登录到一个服务器上。首先,我需要单击按钮“Inloggen”,然后我需要填写用户名和密码,然后再次单击(新建)按钮“Inloggen”
因此,我尝试定位第一个“Inloggen”按钮(使用下面的代码),并尝试单击它,但随后它会引发错误“selenium.common.exceptions.WebDriverException:Message:”,但没有消息

from selenium import webdriver

# go to login page and sign in
driver = webdriver.Firefox()
driver.get("https://www.qassa-nl.be/")

driver.find_element_by_xpath("//a[@title='Inloggen']").click()
其次,如果这样做有效的话,我可以用我猜的经典方式发送我的登录密钥

最好的,

蒂姆

以下是你问题的答案:

下面是打开url
https://www.qassa-nl.be/
,单击LogGen中的按钮
,填写
电子邮件
,填写
密码
,最后单击LogGen中的
按钮:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
caps = DesiredCapabilities().FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get("https://www.qassa-nl.be/")
driver.find_element_by_xpath("//div[@id='personal_info']//a[text()='Inloggen']").click()
driver.find_element_by_xpath("//input[@id='login_username']").send_keys("debanjan")
driver.find_element_by_xpath("//input[@id='login_password']").send_keys("debanjan")
driver.find_element_by_xpath("//button[@title='Inloggen']").click()

如果这能回答您的问题,请告诉我。

嗨!谢谢你的建议。你能解释一下为什么我的方法不管用,而你的方法管用吗?它也可以用于PhantomJS吗?@Tim我只是访问了url
https://www.qassa-nl.be/
通过
get()
方法。现在,脚本将首先查找xpath为
//div[@id='personal\u info']//a[text()='Inloggen']
的元素并单击它。接下来,脚本将查找xpath为
//input[@id='login\u username']
&发送文本
debanjan
。同样,脚本将查找xpath为
//input[@id='login\u password']
&发送文本
debanjan
。最后,脚本将查找xpath为
//button[@title='Inloggen']
的元素并单击它。ThanksHmmm,同样,在更新路径之后,我在页面加载超时上得到了一个错误:selenium.common.exceptions.WebDriverException:Message:unrecogned timeout:page load。另外,我无法真正获得前5行代码(不包括导入);从司机那里。我过去已经用过了。谢谢@蒂姆,请不要为前5行费心。测试人员通常尝试将exe文件和浏览器exe放入Selenium在其系统中方便的位置,Selenium可以轻松获取这些文件和浏览器exe。当我使用多个版本的exe文件和同一浏览器的多个版本时,无论何时何地&无论需要哪个版本,我都会在代码中显式地调用它们。谢谢