Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 类的Xpath_Ruby_Selenium_Xpath - Fatal编程技术网

Ruby 类的Xpath

Ruby 类的Xpath,ruby,selenium,xpath,Ruby,Selenium,Xpath,我正在尝试为模板1查找xpath。到目前为止,我已经尝试了以下内容,但没有任何效果。我正在尝试获取模板1 //a[@class='treenode' and contains(text(),'Template 1')] //div[@id='objTree~templates~750764_children' and text()='Template 1'] //a[contains(@href, 'javascript:void(0)')]/text() //a[contains

我正在尝试为模板1查找xpath。到目前为止,我已经尝试了以下内容,但没有任何效果。我正在尝试获取模板1

    //a[@class='treenode' and contains(text(),'Template 1')]

//div[@id='objTree~templates~750764_children' and text()='Template 1']


//a[contains(@href, 'javascript:void(0)')]/text()
//a[contains(text(), 'Template 1')]

//a[@class='treenode' and starts-with(@href, '/javascript/')]

//a[text()="Template 1"]

//a[normalize-space(.) = 'Template 1']
这是我的HTML

<a class="treenode" href="javascript:void(0)" onclick="; highlightNode(this);" oncontextmenu="return showContext(this);">Template 1</a>

我做错了什么?

您的XPath表达式似乎没有问题,但链接可能是由某些JavaScript动态生成的,因此您不会得到任何TouchElementException,因为它不存在于初始DOM中。您可以尝试等待链接出现在DOM中

我不确定Ruby的语法。试试这个,如果不起作用,请告诉我:

wait = Selenium::WebDriver::Wait.new(:timeout => 15)
element = wait.until { driver.find_element(:link_text  => "Template 1") }
element.click

你用什么工具?是Selenium吗?是的,是Ruby Selenium共享您的Ruby代码alsolink:my_template1,:xpath=>//a[@class='treenode'和containstext,'Template 1']@arm如果您准备好使用Selenium Ruby绑定,请使用WATIR,它是Ruby Selenium绑定的一个很好的包装器,你遇到的时间问题永远不会出现,因为他们处理得很好。什么是:link_text?是xpath吗?不是。它是通过可见链接文本进行搜索。但是如果您想使用XPath,可以将:link_text=>Template 1替换为:XPath=>//a[text='Template 1']。这些定位器实际上是相同的意思
wait = Selenium::WebDriver::Wait.new(:timeout => 15)
element = wait.until { driver.find_element(:link_text  => "Template 1") }
element.click