1

I am trying to automate intranet site. The source code is bunch of tables and consists of hundreds of codes like below:

<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&lt;br/>Price is missing, please update price&lt;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>&nbsp;</td>

I need to capture part number 1360428-0000 and click "editCase (286658)". I have two problems:

  1. Use part number 1360428-0000 as reference to find case number 286658
  2. Imitate click on 286658 with xpath? Couldn't make it work.

I tried to figure out problem #2 using below code with no success:

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()

Any help is appreciated. I also must use IE.

1 Answer 1

1

This is one possible XPath to find the target span by part number "1360428-0000" :

//td[text()='1360428-0000']/preceding-sibling::td[1]/span[@title='Edit case']

xpathtester.com demo

Sign up to request clarification or add additional context in comments.

5 Comments

Is [1] really needed at the end ?
@Newcomer not really, since there is only one span in the td. I rather meant it after td, as in the updated XPath
Solution checks out for source snippet, but not for full source. I am no programmer/webdesigner, but I think code I am dealing with is from hell. It's one big frame with all information about each part (10k+ code). I uploaded bigger snippet to give better idea what it is: Source code(textuploader.com/57o57)
Ok, I was going nuts why no elements were found apart html and it turns out the frame has different url link, so i have been scrapping wrong source code. I used your solution and it worked. Thank you so much! If it's not too much asking, can you help me understand logic behind /preceding-sibling::td[1]/?
Preceding-sibling returns elements, located before the context element at the same level (hence siblings). Index 1 means to return only the one nearest preceding sibling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.