简体   繁体   English

在 Win 10 系统上面对 selenium webdriver 的挑战

[英]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 you need to use IEDriverServer.exe through selenium.webdriver.ie.webdriver.WebDriver() Class as follows:如果您的用例是使用 ,则需要通过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

Update (from @rahuldesai's comment)更新(来自@rahuldesai 的评论)

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.

相关问题 Selenium Webdriver完全下载10个文件后冻结Firefox - Selenium Webdriver freeze Firefox after download exactly 10 files 如何在Windows 10中使用python编写Selenium Webdriver路径地址? - How to write Selenium Webdriver path address with python in Windows 10? 是否有在 python selenium webdriver 中截取屏幕截图以及系统时间戳的解决方案? - Is there a solution for taking screenshot in python selenium webdriver along with system timestamp? Python with Selenium:从文件系统拖放到 webdriver? - Python with Selenium: Drag and Drop from file system to webdriver? Selenium webdriver 无法识别为 webdriver - Selenium webdriver not recognized as webdriver Selenium 挑战 - URL 独立变化 - Selenium Challenge - URL Independently Changing selenium webdriver url 导航(在带有 window10 的 microsoft edge 上),在 28/29 url 之后挂起 - selenium webdriver url navigation (on microsoft edge with window10) , hang after 28/29th url 如何使用python和Selenium Webdriver遍历表并打印前10行的结果? - How to iterate over a table and print the results from the first 10 rows with python and selenium webdriver? 使用Win 10系统使用设备管理器和Py脚本访问所有连接的设备 - Using a Win 10 system to access all connected devices using device manager and Py script 我面临从 web 站点获取表格的挑战 - I'm facing a challenge to get a table from a web site
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM