2017-04-19 44 views
0

选择元素我想选择谷歌API的价值。 我的python版本是2.7。我正在为Google Chrome编写脚本。机器人框架:从谷歌的位置API

当我开始键入文本框的东西,然后在文本框中显示了一些可用的值。就像我输入“Del”一样,那么它会显示如印度德里的建议。

现在我照本宣科,直到在文本字段中输入文本,它也呈现出可用的值。但由于它不是下拉菜单,我无法使用名称或索引从列表中选择值。 我试着按下方向键,但使用ASCII值// 40个按值(在文本字段中。

任何人都可以请建议的解决方案无论是对价值选择或按向下箭头键。

Click element ${Location_Input} 
Press Key ${Location_Input} P 
sleep 4Seconds 
Press Key ${Location_Input} \\40 

结果中: “P(”

回答

0

Press Key ${Location_Input} \\40究竟是干什么的书面文件中,通过代码\\40代表即按ASCII字符(检查出任何ASCII表: http://robotframework.org/Selenium2Library/Selenium2Library.html#Press%20Key

如果你想按非ASCII键,它变得有点难度。 我会建议写对原Selenium2Library的顶部扩展库这样的:

# ExtendedSelenium.py 
from Selenium2Library import Selenium2Library 
from selenium.webdriver.common.action_chains import ActionChains 
from selenium.webdriver.common.keys import Keys 


class ExtendedSelenium(Selenium2Library): 

    def __init__(self): 
     super(ExtendedSelenium, self).__init__() 

    def press_down_arrow(self): 
     """ Emulates action "press down arrow on keyboard". 
     """ 
     ActionChains(self._current_browser()).send_keys(Keys.ARROW_DOWN, Keys.NULL).perform() 

...,然后从你怎么称呼它RF代码:

Library ExtendedSelenium.py 

*** Test Cases *** 
Your Test 
    ... 
    Press Down Arrow 
    ... 
+0

感谢扬快速响应,我非常肯定,这将工作但作为一名初学者,我并不确切知道在哪里以及如何去做。 我所做的是复制你的代码在一个文本文件,它保存为ExtendedSelenium.py文件夹下的C:\ Python27 \ LIB \站点包\ Selenium2Library。并在我的RF代码中提及它并调用向下箭头。但看起来我犯了一些错误。 你能指导我吗? – Prasanna

+0

你有什么错误信息? –

+0

我不停的LIB文件位置在“C:\ Python27 \ Lib文件”,它显示了错误的 启动浏览器启动::浏览器|失败| 找到多个名称为“打开浏览器”的关键字。给你想要使用的关键字的全名: ExtendedSelenium.Open浏览器 Selenium2Library.Open浏览器 – Prasanna