在XPath -Selenium-初学者中使用卷曲括号

发布于 2025-02-05 19:49:08 字数 332 浏览 1 评论 0原文

我正在使用硒,并想通过XPATH识别元素。我想使用的是这样的定位器:

ref_code = driver.find_elements_by_xpath("//tr[@data-eui-handler="{ event:'click',handler: 'eui.app.controller.search_results.selectRow' }"]/td[1]")

以语法错误结束,因为据我所见,字符串中的“事件”和“处理程序”是关键词。我该如何更改它,因此都被视为字符串?

我相信卷曲括号正在结束字符串格式吗?

抱歉,我是新手:)

谢谢 拍

I am using Selenium and want to identify an element via xpath. The locator I want to use looks like this:

ref_code = driver.find_elements_by_xpath("//tr[@data-eui-handler="{ event:'click',handler: 'eui.app.controller.search_results.selectRow' }"]/td[1]")

This ends in a syntax error because as far as I see "event" and "handler" in the string are key words. How can I change it, so it is all seen as a string?

I believe the curly brackets are ending the string format right?

Sorry, I am new to this :)

Thanks
Pat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま昔日黯然 2025-02-12 19:49:08

问题不是括号,而是

使用

ref_code = driver.find_elements_by_xpath("//tr[@data-eui-handler=\"event:'click',handler:'eui.app.controller.search_results.selectRow'}\"]/td[1]")

您需要在之前将\放在之前,如果它们是字符串的一部分,

The issue is not the brackets but the "

Use

ref_code = driver.find_elements_by_xpath("//tr[@data-eui-handler=\"event:'click',handler:'eui.app.controller.search_results.selectRow'}\"]/td[1]")

You need to put an \ before " if they are part of the string

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文