[英]Facing challenge with selenium webdriver on Win 10 system
I am trying to automate login on a website using selenium.我正在尝试使用 selenium 在网站上自动登录。 (Windows 10 64 bit os)
(Windows 10 64 位操作系统)
Using the below code I am able to open a link, But once webpage loads the get cmd does not release my python interpreter next cmd:使用下面的代码我可以打开一个链接,但是一旦网页加载了 get cmd 就不会在下一个 cmd 中释放我的 python 解释器:
browser.find_element_by_class_name('gb_g').click()
does not run.不运行。
I tried to open google.com but the issue is same, I tried different browser it works but my project URL only works with internet explorer.我试图打开 google.com 但问题是一样的,我尝试了不同的浏览器,但我的项目 URL 仅适用于 Internet Explorer。
I have tried with both 64 & 32-bit driver version of internet explorer我已经尝试过 64 位和 32 位驱动程序版本的 Internet Explorer
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
link = 'https://www.google.com/'
browser = webdriver.Ie(executable_path='S:\work\Automation\Elog\IEDriverServer.exe')
browser.get(link)
browser.find_element_by_class_name('gb_g').click()
You need to consider a few things:您需要考虑以下几点:
If your use case is to use internet-explorer you need to use IEDriverServer.exe through selenium.webdriver.ie.webdriver.WebDriver()
Class as follows:如果您的用例是使用internet-explorer ,则需要通过
selenium.webdriver.ie.webdriver.WebDriver()
类使用IEDriverServer.exe ,如下所示:
webdriver.Ie(executable_path=r'S:\\path\\to\\IEDriverServer.exe')
To click()
on the element with text as Gmail you have to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies :要将带有文本的元素上的
click()
作为Gmail,您必须为element_to_be_clickable()
引入WebDriverWait并且您可以使用以下任一定位器策略:
Using LINK_TEXT
:使用
LINK_TEXT
:
from selenium import webdriver browser = webdriver.Ie(executable_path=r'S:\\work\\Automation\\Elog\\IEDriverServer.exe') browser.get("https://www.google.com/") WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Gmail"))).click()
Using CSS_SELECTOR
:使用
CSS_SELECTOR
:
from selenium import webdriver browser = webdriver.Ie(executable_path=r'S:\\work\\Automation\\Elog\\IEDriverServer.exe') browser.get("https://www.google.com/") WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"a.gb_g[href*='com/mail/?tab']"))).click()
Using XPATH
:使用
XPATH
:
from selenium import webdriver browser = webdriver.Ie(executable_path=r'S:\\work\\Automation\\Elog\\IEDriverServer.exe') browser.get("https://www.google.com/") WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.XPATH,"//a[text()='Gmail']"))).click()
Note : You have to add the following imports :注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
With the above mentioned configurations and using the 32 bit IEDriverServer
binary some how the issue gets fixed.使用上述配置并使用32 位
IEDriverServer
二进制文件可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.