我有在硒测试(使用Python和FirefoxWebdriver)。在测试网站我有记录表,我想点击这个表中的元素,但我必须滚动到这个元素,然后我可以点击它。scrollIntoView()滚动到很低
要滚动我用这个方法:
def scroll_to_element(self, element):
try:
self.driver.execute_script("return arguments[0].scrollIntoView();", element)
except Exception as e:
print 'error scrolling down web element', e
但这种方法滚动到多少了。元素是上cca 2行,仍然不可见。有没有其他的方式,真正地滚动到元素?我没有经验过这些脚本。
这里是表:
<table id="idMainGriddata_columns" agname="data_columns" userid="1" entityidcolumnname="dc_id" editable="1" border="0" class="adodb_dbgrid" scrollx="0">
<colgroup>
<col width="25">
# ...
</colgroup>
<tbody>
<tr entityid="14" class="adodb_dbgrid_even_row">
<td class="centered" value="14">...</td>
# ...
</tr>
# ... 400x tr
</tbody>
</table>
,这里是这个方法的用法:
variable = driver.find_element_by_xpath("//table[@id='idMainGriddata_columns']/tbody/tr/td[contains(text(), '" + column + "')]")
st.scroll_to_element(self, variable)
actions = ActionChains(self.driver)
actions.move_to_element(variable)
actions.double_click(variable)
actions.perform()
哪一个你想要点击的确切元素?什么是列值? –
我不想双击整行(并且我点击了td元素,这将访问我想要的行)。我将编辑我的帖子。 – Pivoman
嗯,我想点击行让你的XPath指向它,因为它现在指向td元素。 –