Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Webdriver定位器(使用java)_Java_Selenium_Selenium Webdriver_Xpath_Css Selectors - Fatal编程技术网

Selenium Webdriver定位器(使用java)

Selenium Webdriver定位器(使用java),java,selenium,selenium-webdriver,xpath,css-selectors,Java,Selenium,Selenium Webdriver,Xpath,Css Selectors,我的按钮定位器不工作。为此,我不能再进一步了。我尝试了xpath、cssSelector、ID。这些都不起作用。我上传代码。我是硒的新手。最后一个命令不起作用 public class Upload { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver","E:\\chromedriver_win32\\chromedriver.exe"); WebDr

我的按钮定位器不工作。为此,我不能再进一步了。我尝试了xpath、cssSelector、ID。这些都不起作用。我上传代码。我是硒的新手。最后一个命令不起作用

public class Upload {

  public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver","E:\\chromedriver_win32\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    JavascriptExecutor js = (JavascriptExecutor) driver;
    driver.get("http://888.b7omc88t.io/");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //code for boomcast portal login

    driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[1]/input")).click();
    driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[1]/input")).sendKeys("fatima@ssd-tech.com");
    driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[2]/input")).click();
    driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[2]/input")).sendKeys("1234");
    driver.findElement(By.xpath("/html/body/div[1]/div/div/section/form/div[3]/button")).click();

    driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/div/div[3]/div/ul/li[4]/a")).click();
    driver.findElement(By.xpath("/html/body/div[2]/div/div/div[1]/div/div[3]/div/ul/li[4]/ul/li/a")).click();
    driver.findElement(By.xpath("//*[@id=\"smbscheduleobdStep2\"]")).click();
    driver.findElement(By.xpath("/html/body/div[2]/div/div/div[3]/div/div/div[2]/div/form/div[1]/div[3]/div/div/div/input")).click();
    driver.findElement(By.xpath("/html/body/div[2]/div/div/div[3]/div/div/div[2]/div/form/div[1]/div[3]/div/div/div/input")).sendKeys("01791719879");
    driver.findElement(By.xpath("/html/body/div[2]/div/div/div[3]/div/div/div[2]/div/div[2]/a[3]")).click();
    driver.findElement(By.cssSelector("#content > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > form:nth-child(3) > div:nth-child(5) > div:nth-child(3) > div:nth-child(2) > button:nth-child(1)")).click(); // This line is not getting executed

}
按钮的HTML:

<div class="col-md-3 text-right">
    <button id="smbscheduleobdStep3" type="button" class="btn btn-block">Saved files</button>
</div>

保存的文件

根据您提供的用于单击按钮的HTML,您必须引导WebDriverWait使按钮可单击,并且您可以使用以下代码行:

import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
// other code lines
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='btn btn-block' and @id='smbscheduleobdStep3' and contains(.,'Saved files')]"))).click();
  • 通过FF中的开发工具检查定位器是否工作
  • 定位器可以通过.cssSelector(#smbscheduleobdStep3)简化为
  • 检查元素是否不在框架中,如果不在框架中,则需要使用
    driver.manage().switchTo().frame()在框架中切换

  • 当然也可以像上面提到的那样使用WaitDriver。

    它会给出任何错误吗?如果可能的话,共享元素的html代码。您的代码有很多糟糕的绝对xpath定位器。请把它们修好,因为它们易碎。您使用的css选择器也是脆弱的。请添加HTML以便更好地进行调试和定位器选择。保存的文件谢谢..成功了。我在选择下拉列表时遇到另一个问题。HTML是Select Caller ID或LongNumbers09612773831@Nissan请根据您的新要求提出新问题,StackOverflow志愿者将乐于帮助您。