- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试编写一个脚本来处理具有多个元素的网页。单击此元素将打开一个新窗口。但是我的脚本在识别元素时有问题。我需要帮助来定位元素和处理多个窗口
我尝试使用 Chrome 查找 Xpath,但它在 Internet Explorer 中不一样。我也试过使用 CSS 选择器它不起作用。说是无效的。
函数 test_google_search_page 的代码: def test_google_search_page( self ): 司机=self.driver driver.get("http://xxxx.com ") str1=driver.title 打印(str1)
#get the window handles using window_handles
window_before=driver.window_handles[0]
print(window_before)
#driver.find_element_by_xpath("//* [@id='2ccb50dfc61122820032728dcea648fe']/div/div")
driver.find_element_by_css_selector("#\32 ccb50dfc61122820032728dcea648fe > div > div")
window_after=driver.window_handles[1]
driver.switch_to.window(window_after)
str2=driver.title
print(str2)
print(window_after)
self.assertNotEqual(str1,str2)
print('This window has a different title')
driver.switch_to.window(window_before)
self.assertEqual(str1,driver.title)
print('Returned to parent window. Title now match')
ERROR: test_google_search_page (__main__.GoogleOrgSearch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\Python programs\SNOW2.py", line 21, in test_google_search_page
driver.find_element_by_css_selector("#\32 ccb50dfc61122820032728dcea648fe > div > div")
File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 598, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\PSWN672P\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: An invalid or illegal selector was specified
最佳答案
您的 #\32 ccb50dfc61122820032728dcea648fe > div > div
CSS 选择器确实无效。请引用the CSS selector grammar specification .
您的意思是:#2ccb50dfc61122820032728dcea648fe > div > div
?尽管如此,如果不查看您要查找的页面和元素的 HTML 源代码,就不可能为您提供特定的正确选择器。
2ccb50dfc61122820032728dcea648fe
id 本身虽然看起来是自动生成的,但您可能应该寻找替代定位器来找到所需的元素,本主题可能有助于了解如何使用 selenium 定位元素:
关于python - selenium.common.exceptions.InvalidSelectorException : Message: An invalid or illegal selector was specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54338087/
我正在使用 Appium 自动化 android 应用程序。我正在尝试使用 Android SDK 提供的 UIAutomatorviewer 工具定位元素。以下是我找到的 xpath,但我认为它可能
我对使用 Selenium 非常陌生。我试图单击以下选择按钮: 这是我的代码: import org.openqa.selenium.By; import org.openqa.selenium.We
动机 利用 Selenium 的 CSS 选择器机制以及 CSS 属性选择器和 HTML5 data- 自定义属性来解决元素的特定 Hook 。 问题 当使用上面的方法来定位分配有 CSS 类名和 d
我正在尝试使用 XPATH 从以下内容中检索值 email1、Email2 和 HT email1 Email2 HT 以下是我的 XPATH 代码: int
将 Weblogic 版本从 10.3.6 升级到 12.1.2 后,我得到 javax.jms.InvalidSelectorException 调用 JMS API 时 javax.jms.Que
我正在尝试使用 CssSelector 在我的网页上定位一个元素。我正在使用 Firefox 驱动程序。 这是我使用定位器的方式(我检查过 Selenium IDE 能够用它定位我的元素 [Finds
当我试图从文本框中获取值时,它抛出 No such element found issues, 以下是我的字段属性: input id="altid" class="firstColumnInput
我正在 firefox 中开发 selenium python。我正在尝试通过 css 选择器查找元素 element = "span:contains('Control panel')" my_dr
我正在 firefox 中开发 selenium python。我正在尝试通过 css 选择器查找元素 element = "span:contains('Control panel')" my_dr
我正在尝试编写一个脚本来处理具有多个元素的网页。单击此元素将打开一个新窗口。但是我的脚本在识别元素时有问题。我需要帮助来定位元素和处理多个窗口 我尝试使用 Chrome 查找 Xpath,但它在 In
我正在学习 Selenium Webdriver 并尝试编写一个简单的测试脚本。 目的是获取About Google Gmail 页面上的链接以练习 CSS 定位器。 代码如下: public cla
HTML Welcome 8828024404, MCGM Log Out 要搜索
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the
我以前从未遇到过这样的错误。我正在访问的网站是否无法使用自动化测试? 代码: public class DirectoryAutomation { public static void mai
我正在尝试单击以下 HTML 中的最后一个 span 元素 ... 在Java中使用Selenium,代码如下: driver.fin
我在尝试使用 Selenium 上传文件时遇到问题。由于浏览按钮没有输入标签,我无法使用 sendKeys() 函数传递路径。它是用 Angular 编写的。 这是浏览按钮元素: 我确实在源代码中的
我是一名优秀的程序员,十分优秀!