I'm using Python/Selenium with the Chrome webdriver, and I'm trying to retrieve a url from one <td> based on the content of another <td>. My markup looks like:
<div class="targetclass">
<tr>
<td><a href="[email protected]">emailval2</a></td>
<td><a href="[email protected]">emailval</a></td>
</tr>
</div>
That's easy enough with jQuery and script executor:
with open('jquery-3.2.1.min.js', 'r') as jquery_js:
jquery = jquery_js.read() #read the jquery from a file
driver.execute_script(jquery) # activate the jquery lib
driver.execute_script("$('div.targetclass a[href$=\"[email protected]\"]').parents(\"tr\").find(\"a:first\").attr('href')")
However, when I try to store the returned href to use with webdriver, I have the following result:
aurlval = driver.execute_script("$('div.targetclass a[href$=\"[email protected]\"]').parents(\"tr\").find(\"a:first\").attr('href')")
print (aurlval)
The returned value is
None
How can I store the target url ([email protected]) so that I can manipulate it with the webdriver?