如何使用硒点击带有svg标签的菜单



我想使用selenium点击菜单按钮,但使用WebDriverWait或任何其他方式都无法工作。我如何使用硒点击它https://www.dappradar.com/binance-smart-chain/defi/drip此处

<div class="apexcharts-menu-icon" title="Menu"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0V0z"></path><path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"></path></svg></div>

SVG封装在div标记中,因此您可以定位SVGdiv

我可以用div:

driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("https://dappradar.com/binance-smart-chain/defi/drip")
try:
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@title='Close']"))).click()
print('Clicked on closed icon')
except:
pass
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@title='Menu']"))).click()

进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

我是用Java做的,所以我首先要滚动到我们想要的元素所在的特定位置(底部的某个地方(。然后应用隐式等待,这样我们想要的元素就可以点击了,然后点击它。

WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(100));
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(50));
driver.get("https://dappradar.com/binance-smart-chain/defi/drip");
driver.manage().window().maximize();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,350)", "");
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div[title='Menu']")));
System.out.println("Button enabled:  " + driver.findElement(By.cssSelector("div[title='Menu']")).isDisplayed());
driver.findElement(By.cssSelector("div[title='Menu']")).click();
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("div[class='apexcharts-menu apexcharts-menu-open']")));
List<WebElement> elements = driver.findElements(By.cssSelector("div[class='apexcharts-menu apexcharts-menu-open'] > div"));
System.out.println("List size  " + elements.size());

相关内容

  • 没有找到相关文章

最新更新