gpt4 book ai didi

java - Selenium : Automating LinkedIn - Profile Icon

转载 作者:行者123 更新时间:2023-11-30 07:46:14 25 4
gpt4 key购买 nike

我是 Selenium 的新手,尝试使用 Actions 类将鼠标悬停在网站链接上的个人资料图标上,以打开鼠标悬停在个人资料图像上时显示的菜单。

下面是我的代码,当它到达这些行时,出现错误:无法定位元素..

顶栏链接上的所有可用图标(消息/标志图标等)都会发生这种情况。

代码:

public class LinkedIn {
WebDriver driver = new FirefoxDriver();
@BeforeTest
public void setUp() throws Exception {

String baseUrl = "http://www.linkedin.com/";
driver.get(baseUrl);

}


@Test
public void login() throws InterruptedException
{
WebElement login = driver.findElement(By.id("login-email"));
login.sendKeys("*****@gmail.com");

WebElement pwd = driver.findElement(By.id("login-password"));
pwd.sendKeys("*****");


WebElement in = driver.findElement(By.name("submit"));
in.click();

Thread.sleep(10000);
}


@Test
public void profile() {
// here it gives error to me : Unable to locate element
Actions action = new Actions(driver);
WebElement profile = driver.findElement(By.xpath("//*[@id='img-defer-id-1-25469']"));
action.moveToElement(profile).build().perform();
driver.quit();
}


}

最佳答案

您似乎使用了不正确的 xpath ,请检查以下示例以将鼠标悬停在“消息”按钮上:

            Thread.sleep(5000);
Actions action = new Actions(driver);
WebElement profile = driver.findElement(By.xpath("//*[@id='account-nav']/ul/li[1]"));
action.moveToElement(profile).build().perform();

正确的 Xpath 是:

对于消息图标:"//*[@id='account-nav']/ul/li[1]"

对于连接图标://*[@id='dropdowntest']

上面的代码我刚刚测试过并且运行良好,因此适合您。

关于java - Selenium : Automating LinkedIn - Profile Icon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33911534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com