有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

Java Selenium“findElement”找不到现有对象

昨天我的问题解决后(见下面的链接),新的问题出现了。 首先,上述问题的解决方案仅适用于IE。当我尝试使用相同的代码输入chrome或firefox时(当然,驱动程序除外),我会像开始时一样返回错误消息(在我降级IEDriverServer之前)。见链接

Eclipse Java Selenium failed to connect to localhost

其次。使用findelement函数时不会发生。错误消息“找不到e” 但是,这个元素在那里。这里是应该控制的页面

https://accounts.google.com/signup/v2/webcreateaccount?continue=https%3A%2F%2Fwww.google.de%2F%3Fgws_rd%3Dssl&hl=de&flowName=GlifWebSignIn&flowEntry=SignUp

这个问题已经经常被问到,但不幸的是,答案对我没有帮助。一个解决方案是(因为findelement比浏览器快)安装以下延迟。驾驶员管理()。超时()。隐式等待(5,时间单位秒)

另一个解决方案是搜索id或xpath而不是名称(这就是为什么下面将名称和id列为findelement)。到目前为止还没有成功。没有在字段中输入提到的密钥(密码和名字等,我已经尝试过)

以下是与我的问题最接近但对我没有帮助的文章。 No such element exception | Internet explorer

Same CSS Slector Not Working in Internet Explorer but works in firefox

无论如何。IE将打开,但不会有其他浏览器,也不会填充任何元素。这里是代码和错误消息

import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.grid.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.concurrent.TimeUnit;


public class firefoxöffner {




    public static void main(String[] args) throws IOException, URISyntaxException {
        System.setProperty("webdriver.gecko.driver","./geckodriver");

        String service = "D://IEDriverServer.exe";
        System.setProperty("webdriver.ie.driver", service);
        InternetExplorerDriver  driver = new InternetExplorerDriver();


        driver.get("https://accounts.google.com/signup/v2/webcreateaccount?flowName=GlifWebSignIn&flowEntry=SignUp");

        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        WebElement myDynamicElement = driver.findElement(By.id("lastName"));

        driver.findElement(By.id("lastName")).sendKeys("B");
        driver.findElement(By.name("lastName")).sendKeys("A");
    }
}

已启动InternetExplorerDriver服务器(64位) 3.8.0.0 监听端口47620 只允许本地连接 2018年5月6日11:29:28 NACHM。组织。openqa。硒。遥远的协议握手会话 信息:检测到的方言:W3C 线程“main”组织中出现异常。openqa。硒。NoSuchElementException:找不到css选择器为=#lastName的元素

再次感谢


共 (2) 个答案

  1. # 1 楼答案

    在IE上运行时//*[@id="lastName"]可能无法提供您想要使用的确切元素。相反,什么时候可以尝试像下面这样提供Xpath

    //*[@id="lastName"]//following-sibling::div"
    
  2. # 2 楼答案

    如果您使用Java+Selenium进行Web界面测试,我建议您使用NoraUi开源框架

    该框架管理IE webdriver、Chrome webdriver和FF webdriver