Reputation: 22440
I've written a script in python in combination with selenium to initiate a click on a certain link in a webpage. My only intention is to click on that link. I've tried few different ways but I can't get it working.
Link to the webpage: URL
Script I have tried with:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("use_above_url")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".k-selectable"))).click()
driver.quit()
Elements within which the clickable link should lie within:
<div class="k-grid-content k-auto-scrollable">
<table class="k-selectable" data-role="selectable" role="grid" style="touch-action: none;">
<colgroup>
<col style="width:100px"/>
<col style="width:210px"/>
<col/>
<col/>
<col style="width:120px"/>
</colgroup>
<tbody role="rowgroup">
<tr class="rowHover" data-uid="1fccd732-cd65-4393-b1be-66786fe9ee60" role="row">
<td role="gridcell">
R016698
</td>
<td role="gridcell">
R-13-0410-0620-50000
</td>
<td role="gridcell" style="display:none">
O0485204
</td>
<td role="gridcell">
GOOCH, PHILIP L
</td>
<td role="gridcell">
319 LIZZIE ST, TAYLOR, TX 76574
</td>
<td role="gridcell" style="display:none">
DOAK ADDITION, BLOCK 62, LOT 5
</td>
<td role="gridcell" style="display:none">
T541
</td>
<td role="gridcell" style="display:none">
</td>
<td role="gridcell" style="display:none">
S3564 - Doak Addition
</td>
<td role="gridcell" style="display:none">
Real
</td>
<td role="gridcell">
<div style="text-align:right;width:100%">
$46,785
</div>
</td>
</tr>
</tbody>
</table>
</div>
If you follow the above url then you can see a line in that webpage containing this exact text R016698 R-13-0410-0620-50000 GOOCH, PHILIP L 319 LIZZIE ST, TAYLOR, TX 76574
. That is where I wish to click. When you hover your mouse over that link, a shadow is noticed across the link. Hope it is clear what I wanna do. Thanks in advance.
Upvotes: 2
Views: 54
Reputation: 52665
There are two elements with class "k-selectable"
on page. The first one is hidden, so waiting for EC.visibility_of_element_located
will always fail... You need to handle the second one. So just apply more specific selector:
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".k-selectable tr[role='row']"))).click()
Upvotes: 2