Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.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 Internet explorer中的Selenium Webdriver_Java_Internet Explorer_Selenium Webdriver - Fatal编程技术网

Java Internet explorer中的Selenium Webdriver

Java Internet explorer中的Selenium Webdriver,java,internet-explorer,selenium-webdriver,Java,Internet Explorer,Selenium Webdriver,我已经使用seleniumwebdriver和java实现了登录功能的自动化,并使用chrome驱动程序执行了该功能 它工作得很好。然后我尝试使用internet explorer执行它 但是我得到了“无法定位元素” 我如何解决这个问题 代码: /*无需输入用户名即可登录*/ @测试(优先级=0) HTML: <head> <body class="game-play game-login"> <div id="page"> <form id="form

我已经使用selenium
webdriver
和java实现了登录功能的自动化,并使用chrome驱动程序执行了该功能

它工作得很好。然后我尝试使用
internet explorer执行它

但是我得到了“无法定位元素”

我如何解决这个问题

代码:

/*无需输入用户名即可登录*/

@测试(优先级=0)

HTML:

<head>
<body class="game-play game-login">
<div id="page">
<form id="form1" method="post" action="./">
<div class="aspNetHidden">
<script type="text/javascript">
<input id="email_hidden" name="email_hidden" value="2" type="hidden">
<input id="username_hidden" name="username_hidden" value="2" type="hidden">
<input id="profilepath_hidden" name="profilepath_hidden" value="2" type="hidden">
<div class="container fluid">
<div class="content-wrap">
<main id="main-section" class="transition page-in">
<div class="main-content">
<div class="game-login-wrap">
<section class="gme-ply-head">
<section class="center-pin">
<div class="title-head">
<ul class="log-reg clearfix">
<li class="active">Login</li>
<li>
</ul>
</div>
<div class="field-input">
<div class="login__row">
<input id="emailtxt" class="login__input email" name="emailtxt" placeholder="Email" type="text">
<span class="log-icon">
</div>
<div class="login__row scn-top">
<input id="passwordtxt" class="login__input pass" name="passwordtxt" placeholder="Password" type="password">
<span class="log-icon">
</div>
</div>

  • 登录

尝试使用
ExplicitWait
检查元素是否存在,然后执行操作

WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='main-section']/div/div/section[2]/div[1]/ul/li[1]")));

 // Do your actions

用chrome编写的XPath通常不能与internet explorer配合使用

使用给定的HTML代码段,并假设登录名包装在'li'标记中作为登录链接,您可以尝试使用以下xpath:

//li[text()='Login']

您面临哪个异常?org.openqa.selenium.NoSuchElementException:无法找到xpath==/*[@id='main-section']]/div/div/section[2]/div[1]/ul/li[1]执行代码时,元素在页面上清晰可见。还是等着吧。但是没有用。我也遇到了同样的错误。你能添加一些html和你的代码片段吗?因为很难判断发生了什么
//li[text()='Login']