我无法使用selenium单击下拉元素
我想点击“Mon profil” 我试过:我无法使用selenium单击下拉元素,selenium,automation,dropdown,Selenium,Automation,Dropdown,我想点击“Mon profil” 我试过: driver.findElement(By.className("profile-navbar-label dropdown-item")).click() 及 它不起作用 试试这个Xpath driver.findElement(By.xpath("//button[contains(.,'Mon profil')]")).click() 或 不能使用带空格的类名来查找元素。如果你想使用这样的类名,你必须为此编写xpath。所以第一种查找方法是
driver.findElement(By.className("profile-navbar-label dropdown-item")).click()
及
它不起作用
试试这个
Xpath
driver.findElement(By.xpath("//button[contains(.,'Mon profil')]")).click()
或
不能使用带空格的类名来查找元素。如果你想使用这样的类名,你必须为此编写xpath。所以第一种查找方法是错误的,关于
xpath
我不确定这是否是写xpath的正确方法
试试这个xpath=(.//button[@type='button'])[1]
它会工作的
通过单击F12,然后单击
ctrl+F
,可以检查xpath是否找到了正确的web元素。输入xpath
它将突出显示webelement。首先您应该单击选择框,当显示下拉列表时,使用以下代码
driver.findElement(By.xpath("//button[text()='Mon profil']")).click()
或
请不要将代码作为截图。您可以从浏览器调试控制台将代码复制并粘贴到问题中。阅读截图中的代码太难了。
driver.findElement(By.xpath("//button[text()='Mon profil']")).click()
driver.findElement(By.xpath("//button[text()='Mon profil']")).click()
WebElement = driver.findElement(By.xpath("//button[text()='Mon profil']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", webElement);