Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Java Selenium:我无法选择选项";今日销售更新“;通过我的代码_Java_Selenium - Fatal编程技术网

Java Selenium:我无法选择选项";今日销售更新“;通过我的代码

Java Selenium:我无法选择选项";今日销售更新“;通过我的代码,java,selenium,Java,Selenium,我添加了硒测试。在这个测试中,我可以单击employee,但无法单击“Today Sale update”。我怎样才能做到 请检查我的代码 package Testing; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Selec

我添加了硒测试。在这个测试中,我可以单击employee,但无法单击“Today Sale update”。我怎样才能做到

请检查我的代码

package Testing;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Login {

    public static void main(String\[\] args) {
        WebDriver driver= new FirefoxDriver();
        String baseurl="http://203.212.70.20/vid/WebLogin.aspx ";
        driver.get(baseurl);
        driver.manage().window().maximize();
        driver.findElement(By.id("textBoxUserName")).sendKeys("admin");
        driver.findElement(By.id("textBoxPassword")).sendKeys("1234");
        driver.findElement(By.id("explore")).click();
        driver.findElement(By.id("ui-accordion-accordion-header-2")).click();
        driver.findElement(By.xpath("//*\[@id="ui-accordion-accordion-panel-2"\]/ul/li\[6\]/a")).click();
        //Select oSelection = new Select(driver.findElement(By.id("ui-accordion-accordion-header-2")));
        //oSelection.selectByVisibleText("TODAY SALE UPDATE");
        driver.findelement(By.visibleText(""))
        driver.findElement(arg0)

        //oSelection.selectByIndex(1);

        // TODO Auto-generated method stub

    }

正如HTML所示,您尝试单击的选项是列表项中的URL

  • 元素“TODAY SALE UPDATE”是一个列表项,不是选择选项,因此您将永远无法在其上使用selenium的选择类。相反,您可以将所有列表项存储在一个列表中,然后根据需要单击某个项。单击登录页面中的“浏览”按钮后,您可以执行以下操作。试试看-

    wd.findElement(By.id("ui-accordion-accordion-header-2")).click();
        WebElement web=wd.findElement(By.id("ui-accordion-accordion-panel-2"));
    
        List<WebElement> list=web.findElements(By.tagName("li"));
        for(WebElement w:list){
            if(w.getText().equalsIgnoreCase("today sale update")){
                w.click();
            }
        }
    
    wd.findElement(By.id(“ui-accordion-accordion-header-2”)。单击();
    WebElement web=wd.findElement(By.id(“ui-accordion-accordion-panel-2”);
    列表=web.findElements(按.tagName(“li”));
    for(WebElement w:list){
    if(w.getText().equalsIgnoreCase(“今日销售更新”)){
    w、 单击();
    }
    }
    
    检查元素是否具有id属性。
    driver.findElement(By.visibleText(“今日销售更新”))。单击()不起作用?会发生什么?你有错误吗?