我在这里使用linkedin来实现学习目的&想要对编辑个人资料=>执行操作工作经验=>添加位置。在这里"添加位置"按钮来自工作经验,在悬停到特定区域时变得可见。看看我的代码,
driver.findElement(By.id("login-email")).clear();
driver.findElement(By.id("login email")).sendKeys("email id");
driver.findElement(By.id("login-password")).clear();
driver.findElement(By.id("login-password")).sendKeys("password");
driver.findElement(By.name("submit")).click();
driver.findElement(By.linkText("Home")).click();
driver.findElement(By.linkText("Profile")).click();
Thread.sleep(3000);
/ *向下滚动页面* /
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("window.scrollBy(0,250)", "");
/ *将鼠标悬停在所需选项* /
上Actions hover=new Actions(driver);
hover.moveToElement(driver.findElement(By.xpath("id('background-experience')/div[1]/div/button[1]")));
driver.findElement(By.xpath("id('background-experience')/div[1]/div/button[1]")).click();
Thread.sleep(5000);
/ *编辑公司名称* /
driver.findElement(By.xpath("id('companyName-positionCompany-position-editPositionForm')")).clear();
driver.findElement(By.xpath("id('companyName-positionCompany-position-editPositionForm')")).sendKeys("testing company");
这是继续编辑工作细节,但当我执行时,它会停止工作经验和页面的页面。无法单击添加位置按钮来编辑工作。 它给"编辑公司"提供了错误。代码行。任何人都可以帮我执行相同的操作吗?
答案 0 :(得分:0)
//Hover
Actions actions = new Actions(driver);
IWebElement menuHoverLink = driver.FindElement(By.XPath("//*[@id='background-experience']/div[1]/div/button[1]"));
actions.MoveToElement(menuHoverLink);
actions.Build().Perform();
driver.FindElement(By.XPath("//*[@id='background-experience']/div[1]/div/button[1]")).Click();