WebElement n=driver.findElement(By.cssSelector("tr:nth-of-type(1) > td:nth-of-type(7)"));
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript("arguments[0].click();", n);
網頁
<td class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignLeft"><span class="more-icon "><svg class="MuiSvgIcon-root" focusable="false" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"></path></svg></span></td>
我也嘗試了動作類和 javaexecute,但它沒有用。
uj5u.com熱心網友回復:
我認為您正在嘗試單擊 SVG 影像,該影像的處理方式與傳統元素不同。
driver.find_element(By.XPATH, "//*[name()='svg' and @class='MuiSvgIcon-root')]")
如果您嘗試單擊 svg,這應該可以作業。如果 DOM 中只有一個 svg 元素,那么像下面這樣的簡單 svg 定位器應該可以作業。
driver.find_element(By.XPATH, "//*[name()='svg']")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/473998.html
