我尝试编写一个代码,点击表格中的几个链接。
以下是HTML代码:
<div id="gadget-34365" class="gadget-inline" style="height: 905px;">
<div class="results-wrap search-results-dashboard-item">
<div class="search-results-dashboard-item-issue-table ">
<issuetable-web-component>
<table class="issue-table">
<thead></thead>
<tbody>
<tr rel="548420" data-issuekey="SOLI-30715" class="issuerow"></tr>
<tr rel="532948" data-issuekey="SOLI-29811" class="issuerow"></tr>
<tr rel="548424" data-issuekey="SOLI-30719" class="issuerow">
<td class="priority"></td>
<td class="issuetype"></td>
<td class="issuekey">
<a class="issue-link" data-issue-key="SOLI-30719" href="https://jira.t-systems-mms.eu/browse/SOLI-30719">SOLI-30719</a>
</td>
<td class="summary"></td>
<td class="status"></td>
<td class="customfield_10090">
<span title="26.12.17">
<time datetime="2017-12-26">26.12.17</time>
</span>
</td>
<td class="issue_actions"> </td>
</tr>
<tr rel="553117" data-issuekey="SOLI-31203" class="issuerow"></tr>
<tr rel="550261" data-issuekey="SOLI-30912" class="issuerow"></tr>
</tbody>
</table>
</issuetable-web-component>
</div>
</div>
如果项目必须在接下来的两周内完成,我的代码应检查“customfield_10090”列中的表格。之后,它应该点击“issuekey”列中的链接。
到目前为止,这是我的代码:
td_list = WebDriverWait(driver, 10).until(lambda driver: driver.find_elements_by_css_selector("#gadget-34365 > div > div"))
for td in td_list:
time = driver.find_elements_by_tag_name("time")
for row in driver.find_elements_by_css_selector("#gadget-34365 > div > div > issuetable-web-component > table > tbody > tr:nth-child(7) > td.customfield_10090"):
if time == now or now <= date_in_two_weeks:
for cell in driver.find_elements_by_class_name("issuekey"):
Link = driver.find_element_by_link_text("SOLI")
Link.click()
driver.get_screenshot_as_file("Test.png")
else:
print "No Projects found in the next two weeks !"
我尝试了我能在这里找到的每一个解决方案,但没有什么能解决我的问题。
我错过了什么或错了什么?希望有人可以提供帮助:)
编辑:
这是我得到的错误:
Traceback (most recent call last):
File "comment.py", line 42, in <module>
Link = driver.find_element_by_link_text("SOLI")
File "/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py", line 389, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 843, in find_element
'value': value})['value']
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element:
Unable to locate element: {"method":"link text","selector":"SOLI"}
(Session info: chrome=62.0.3202.75)
(Driver info: chromedriver=2.26.436382
(70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.9.17-c9 x86_64)
答案 0 :(得分:0)
您的css选择器似乎有误。
您尝试选择tr:nth-child(7)
,但我认为它应该是tr:nth-child(3)
答案 1 :(得分:0)
您要查找的元素的链接文本与#34; SOLI&#34;不匹配,而是#34; SOLI-30719&#34;。从
更改选择器 driver.find_element_by_link_text("SOLI")
到
driver.find_element_by_partial_link_text("SOLI")
希望有所帮助。