我想为以下流程编写xpath
:
- 转到 au.support.tomtom.com
- 单击页脚中的国旗标志。
- 选择澳大利亚作为国家/地区
到目前为止我已经尝试过:
driver.get("http://au.support.tomtom.com/");
driver.findElement(By.xpath(".//*[@id='rn_PageFooter_16']/footer/div[3]/button")).click();
driver.findElement(By.xpath("//a[@href='//au.support.tomtom.com/app/answers/list/locale/en_AU']//[@text()='Australia']")).click();
最后一个 xpath
不工作。
我正在使用 selenium JavaScript。请帮忙。
最佳答案
我认为是您的 xpath 导致了问题,而且您的元素不在 View 中可点击
下面的代码已经过测试并适用于我
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class test1 {
@Test
public void chec() throws InterruptedException{
System.setProperty("webdriver.chrome.driver","C://Temp//imp//chromedriver.exe");
WebDriver d = new ChromeDriver();
d.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);
d.get("http://au.support.tomtom.com/");
d.manage().window().maximize();
JavascriptExecutor jse = (JavascriptExecutor)d;
d.findElement(By.xpath(".//*[@id='rn_PageFooter_16']/footer/div[3]/button")).click();
Thread.sleep(5000);
jse.executeScript("scroll(0, -250);");
d.findElement(By.xpath("html/body/div[4]/div/div[2]/footer/div[2]/div/div/div/div[1]/div/div[1]/div/div[2]/ul/li[1]/a")).click();
}
}
关于javascript - Selenium 中的 Xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36592798/