Selenium python 点击 span class
Selenium python click on span class
我正在尝试自动化 Intranet 站点。源代码是一堆表格,由数百个代码组成,如下所示:
<span id="GridView1_ctl51_lblCaseType"></span>
</td><td nowrap="nowrap">
<span class="fakeLink" title="Edit case" onmouseenter="this.focus()" onclick="editCase('286658')"> 286658</span>
</td><td nowrap="nowrap">1360428-0000</td><td align="center" style="color:Red;">
<span id="GridView1_ctl51_Label2">13,0</span>
</td><td align="center">
<span id="GridView1_ctl51_Label2">8,8</span>
</td><td align="center">
<span id="GridView1_ctl51_Label9">R</span>
</td><td>
<span id="GridView1_ctl51_Label6">Waiting for info fr. suppl.</span>
</td><td>
<span id="GridView1_ctl51_Label11" title="1360428-0000 Condensate Cup<br/>Price is missing, please update price<br/>(enquiry by Name 11/1)" class="vtip">1360428-0000 Co</span>
</td><td>
<span id="GridView1_ctl51_Label12" title="Please source" class="vtip">Please source</span>
</td><td>
<span id="GridView1_ctl51_Label7">Fname Lname</span>
</td><td>
<span id="GridView1_ctl51_Label1"></span>
</td><td>
<span id="GridView1_ctl51_Label8">Price or delivery time missing</span>
</td><td>
<span id="GridView1_ctl51_Label3">A21</span>
</td><td>
<span id="GridView1_ctl51_Label10">TS6</span>
</td><td>
<span id="GridView1_ctl51_Label5">FName Lname</span>
</td><td> </td>
我需要获取零件号 1360428-0000 并单击 "editCase (286658)"。我有两个问题:
- 使用零件号 1360428-0000 作为参考查找案例号 286658
- 用xpath模拟点击286658?无法正常工作。
我尝试使用以下代码解决问题 #2 但没有成功:
def IeTest():
driver = webdriver.Ie("C:\Python34\IEDriverServer.exe")
driver.get("http://intranet.company.com")
time.sleep(3)
print(driver.title)
elem = driver.find_element_by_xpath('//span[contains(@onclick,"286658")]')
elem.click()
IeTest()
感谢任何帮助。我也必须使用IE。
这是一种可能的 XPath,可以通过部件号 "1360428-0000"
找到目标 span
:
//td[text()='1360428-0000']/preceding-sibling::td[1]/span[@title='Edit case']
我正在尝试自动化 Intranet 站点。源代码是一堆表格,由数百个代码组成,如下所示:
<span id="GridView1_ctl51_lblCaseType"></span>
</td><td nowrap="nowrap">
<span class="fakeLink" title="Edit case" onmouseenter="this.focus()" onclick="editCase('286658')"> 286658</span>
</td><td nowrap="nowrap">1360428-0000</td><td align="center" style="color:Red;">
<span id="GridView1_ctl51_Label2">13,0</span>
</td><td align="center">
<span id="GridView1_ctl51_Label2">8,8</span>
</td><td align="center">
<span id="GridView1_ctl51_Label9">R</span>
</td><td>
<span id="GridView1_ctl51_Label6">Waiting for info fr. suppl.</span>
</td><td>
<span id="GridView1_ctl51_Label11" title="1360428-0000 Condensate Cup<br/>Price is missing, please update price<br/>(enquiry by Name 11/1)" class="vtip">1360428-0000 Co</span>
</td><td>
<span id="GridView1_ctl51_Label12" title="Please source" class="vtip">Please source</span>
</td><td>
<span id="GridView1_ctl51_Label7">Fname Lname</span>
</td><td>
<span id="GridView1_ctl51_Label1"></span>
</td><td>
<span id="GridView1_ctl51_Label8">Price or delivery time missing</span>
</td><td>
<span id="GridView1_ctl51_Label3">A21</span>
</td><td>
<span id="GridView1_ctl51_Label10">TS6</span>
</td><td>
<span id="GridView1_ctl51_Label5">FName Lname</span>
</td><td> </td>
我需要获取零件号 1360428-0000 并单击 "editCase (286658)"。我有两个问题:
- 使用零件号 1360428-0000 作为参考查找案例号 286658
- 用xpath模拟点击286658?无法正常工作。
我尝试使用以下代码解决问题 #2 但没有成功:
def IeTest():
driver = webdriver.Ie("C:\Python34\IEDriverServer.exe")
driver.get("http://intranet.company.com")
time.sleep(3)
print(driver.title)
elem = driver.find_element_by_xpath('//span[contains(@onclick,"286658")]')
elem.click()
IeTest()
感谢任何帮助。我也必须使用IE。
这是一种可能的 XPath,可以通过部件号 "1360428-0000"
找到目标 span
:
//td[text()='1360428-0000']/preceding-sibling::td[1]/span[@title='Edit case']