无法使用Robocorp Selenium库获取XPath选择器来工作

huangapple go评论58阅读模式
英文:

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]

元素的快照:

无法使用Robocorp Selenium库获取XPath选择器来工作

我用红色圈出了这个元素 ^^^

在这个页面上,我无法让选择器被识别。我尝试添加延迟,等待元素激活,等待元素可见等等。

似乎什么都不起作用。

无法使用Robocorp Selenium库获取XPath选择器来工作

这是我尝试选择的元素的图像。
(href元素中的链接将我带到我想要访问的页面)。

我以为第三个一定会起作用,但仍然失败。

我正在使用一个名为Robocorp的平台,它只需要原始选择器(CSS或XPath)来工作。

无法使用Robocorp Selenium库获取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:

无法使用Robocorp Selenium库获取XPath选择器来工作

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.

无法使用Robocorp Selenium库获取XPath选择器来工作

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)

无法使用Robocorp Selenium库获取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:

huangapple
  • 本文由 发表于 2023年2月14日 02:57:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75440149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定