Android:在webview中使用javascript单击没有id或类的链接
我需要执行一个特定的链接点击。不幸的是,我无法控制html页面,我所拥有的是:Android:在webview中使用javascript单击没有id或类的链接,javascript,android,class,click,Javascript,Android,Class,Click,我需要执行一个特定的链接点击。不幸的是,我无法控制html页面,我所拥有的是: <table width="10%" height="44px" cellspacing="0px" border="0" padding="0px"> <tbody> <tr> <td> <a href="https://www.example.com/test"> <img border="0" src="https://www.example.c
<table width="10%" height="44px" cellspacing="0px" border="0" padding="0px">
<tbody>
<tr>
<td>
<a href="https://www.example.com/test">
<img border="0" src="https://www.example.com/images/img.png">
</a>
</td>
<td>
<a href="https://www.example.com/test2">
<img border="0" src="https://www.example.com/images/img2.png">
</a>
</td>
</tr>
</tbody>
</table>
我得到这个错误:
未捕获类型错误:document.getElementsById不是函数
问题是您不能对自身重复调用
getElementsByTagName()
——该函数返回元素的HTMLCollection
,并且getElementsByTagName()
函数不能再次应用于该函数
一种替代方法可以是:
document.getElementsByTagName('table')[0].childNodes[0].childNodes[x].childNodes[y].click()
document.getElementsByTagName('table')[0].childNodes[0].childNodes[x].childNodes[y].click()