英文:
Cannot get XPath selector to work using Robocorp Selenium library
问题
我正在使用一个名为Robocorp的平台以及Selenium库进行网页自动化。
当我运行我的程序时,直到我遇到这个页面时都没有问题,我尝试点击上面写着SQL的图标。
我想要获取具有@href
属性的<a>
元素。
以下是我尝试过的一些(众多)XPath,它们都失败了:
xpath://a[contains(@href,'sql_form.jsp')]
xpath://*[text()='SQL']
xpath://a[@target='frame2]
元素的快照:
我用红色圈出了这个元素 ^^^
在这个页面上,我无法让选择器被识别。我尝试添加延迟,等待元素激活,等待元素可见等等。
似乎什么都不起作用。
这是我尝试选择的元素的图像。
(href元素中的链接将我带到我想要访问的页面)。
我以为第三个一定会起作用,但仍然失败。
我正在使用一个名为Robocorp的平台,它只需要原始选择器(CSS或XPath)来工作。
英文:
I am attempting web automation with a platform called Robocorp using the Selenium library.
When I run my program, I have no issues until I encounter this page where I am trying to get the program to click on the icon that says SQL.
I want the <a>
element with the @href
attribute.
Here are some (of many) XPaths I have tried that have all failed:
xpath://a[contains(@href,'sql_form.jsp')]
xpath://*[text()='SQL']
xpath://a[@target='frame2]
Snapshot of the element:
I circled the element in red ^^^
I cannot get the selector to be recognized on this page. I have tried adding delays, waiting until the element is active, waiting until the element is visible, etc.
Nothing seems to work.
Here is an image of the elements I am trying to select.
(The link in the href element takes me to the page I am trying to access).
I thought that the third one would for sure work but is still failing.
I am using a platform called Robocorp which only needs the raw selector to work (CSS or XPath)
答案1
得分: 2
我不知道 iframe 需要以不同方式处理,甚至不知道它的存在
https://robocorp.com/docs/development-guide/browser/how-to-work-with-iframes
我首先需要切换框架。
英文:
I was unaware that iframe needed to be handled differently or that it even existed
https://robocorp.com/docs/development-guide/browser/how-to-work-with-iframes
I first needed to switch frames.
答案2
得分: 1
要识别具有文本为“SQL”的元素,您可以使用以下任一定位策略:
-
使用“等待元素可见”:
Wait Until Element Is Visible xpath=//a[starts-with(@href, 'sql_form.jsp') and @target='frame2']/font[text()='SQL'] 10 seconds
-
使用“等待元素启用”:
Wait Until Element Is Enabled xpath=//a[starts-with(@href, 'sql_form.jsp') and @target='frame2']/font[text()='SQL'] 10 seconds
参考资料
您可以在以下链接找到一些相关的详细讨论:
英文:
To identify the element with text as SQL you can use you can use either of the following locator strategies:
-
Using
Wait Until Element Is Visible
:Wait Until Element Is Visible xpath=//a[starts-with(@href, 'sql_form.jsp') and @target='frame2']/font[text()='SQL'] 10 seconds
-
Using
Wait Until Element Is Enabled
:Wait Until Element Is Enabled xpath=//a[starts-with(@href, 'sql_form.jsp') and @target='frame2']/font[text()='SQL'] 10 seconds
References
You can find a couple of relevant detailed discussions in:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论