我不能点击按钮有一些可见度的问题。我需要在这里盘旋首先得到的链接,然后我需要点击相同的。
<a tabindex="0"
class="cardPreviewLink expand-icon"
aria-label="card opens in new tab"
target="_blank"
id="card-preview-link-19479"
href="/card/19479?$filters@$pattern=10532372&type===&dimension=chargeback_id">
<button class="MuiButtonBase-root MuiIconButton-root" tabindex="-1" type="button">
<span class="MuiIconButton-label">
<svg class="MuiSvgIcon-root open-icon"
focusable="false"
viewBox="0 0 24 24"
aria-hidden="true"
role="presentation">
<path d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"/>
</svg>
</span>
</button>
</a>法典审判:
WebDriverWait wait4 = new WebDriverWait(driver, 60);
wait4.until(ExpectedConditions.visibilityOfElementLocated(By.className("cardPreviewLink expand-icon")));
driver.findElement(By.className("cardPreviewLink expand-icon")).click();错误:
Timeout Exception because of No such Element Exception发布于 2020-01-18 10:15:51
您可以尝试使用webdriver wait单击element to receive click。
By buttonBy = By.cssSelector("a.cardPreviewLink.expand-icon > button"));
WebDriverWait wait = new WebDriverWait(driver, 50);
wait.until(ExpectedConditions.elementToBeClickable(buttonBy);如果以上方法不起作用,您可以尝试使用click using JS。在这里,我只是在等待visibility of element,就好像元素可以接收到单击一样,那么第一种方法应该可以工作。
wait.until(ExpectedConditions.visibilityOfElementLocated(buttonBy);
WebElement button=driver.findElement(buttonBy);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", button);发布于 2020-01-17 12:24:56
所需的元素是一个动态元素,因此要对元素进行click(),您必须为elementToBeClickable()引入WebDriverWait,您可以使用以下任何一个Locator Strategies
cssSelector:新的20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.cardPreviewLink.expand-icon (驱动程序,span.MuiIconButton-label"))).click();
xpath:>button.MuiButtonBase root.MuiIconButtonroot>span.MuiIconButton-label“))).click();
xpath:)新的20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a@class='cardPreviewLink (驱动程序,MuiIconButton-root'/span@class='MuiIconButton-label'"))).click();展开-图标‘/WebDriverWait@class=’MuiButtonBase MuiIconButton-root‘/span@class=’MuiIconButton-label‘“))).click();
发布于 2020-01-18 04:48:51
By.className()不能处理具有空格的名称-- cardPreviewLink展开-图标。相反,尝试使用cssSelector或xpath。
Xpath示例:
WebDriverWait wait4 = new WebDriverWait(driver, 60);
WebElement element = wait4.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[contains(@class,'cardPreviewLink'][contains(@class,'expand-icon']")));
element.click();“visibilityOfElementLocated”应该能用。如果没有,就像Debanjan提到的那样,尝试使用'elementToBeClickable‘。
另外,wait.until本身将返回WebElement对象。你可以用同样的方式点击它。
https://stackoverflow.com/questions/59786864
复制相似问题