无法在selenium

时间:2017-06-24 04:35:09

标签: selenium xpath selenium-webdriver

我正在naukri.com网站上学习selenium webdriver练习写脚本。

我想在更新配置文件下单击左侧的“附加恢复”链接,但是显示“无法找到元素”。 我试图用xpath找到元素

driver.findElement(By.linkText(" Attached Resume")).click();

我甚至尝试过同样的错误。

以下是HTML示例

<div id="leftNav_updateProfile" class="leftNavBullet">
<ul>
<li>
<a href="//my.naukri.com/Profile/edit?id=&altresid=">
<a href="//my.naukri.com/Profile/editSummary?id=&altresid=">
<a href="//my.naukri.com/EmploymentDetails/add?id=&altresid=">
<a href="//my.naukri.com/Profile/view/subAction/ar?id=&altresid=#ar">
<span class="gryTxt">• </span>
Attached Resume
</a>
<a href="//my.naukri.com/ITProjects/add?id=&altresid=">
<a href="//my.naukri.com/ITSkills/edit?id=&altresid=">
<a href="//my.naukri.com/EducationDetails/edit?id=&altresid=">
<a href="//my.naukri.com/ProfileShowcase/edit?id=&altresid=">
<a href="//my.naukri.com/OtherInfo/edit?id=&altresid=">
</li>
</ul>
</div>

这是我的剧本

package practice;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;

public class UploadResume {

    public static void main(String[] args) 
    {
        System.setProperty("webdriver.gecko.driver", "E:\\geckodriver-v0.16.1-win32\\geckodriver.exe");
         WebDriver driver=new FirefoxDriver();
         driver.get("https://www.naukri.com/");
         driver.findElement(By.xpath("//div[text()='Login']")).click();
         driver.findElement(By.id("eLogin")).sendKeys("xyz@gmail.com");
         driver.findElement(By.id("pLogin")).sendKeys("12345");
         driver.findElement(By.xpath("//button[text()='Login']")).click();
         driver.findElement(By.xpath("//div[@id='leftNav_updateProfile']//a[contains(.,' Attached Resume')]")).click();
         driver.findElement(By.id("uploadLink")).click();
         driver.findElement(By.id("attachCV")).click();

    }

}

4 个答案:

答案 0 :(得分:0)

正如您所看到的那样,锚标记有文字&#34;。&#34;在第一个跨度中,因此链接文本&#34;附加简历&#34;不行。

<强> HTML:

<a href="//my.naukri.com/Profile/view/subAction/ar?id=&altresid=#ar">
<span class="gryTxt">• </span>
Attached Resume
</a>

请使用以下Xpath:

  

// div [@id =&#39; leftNav_updateProfile&#39;] // a [包含(。,&#39;附加简历&#39;)]

答案 1 :(得分:0)

你能检查一下,

driver.findElement(By.linkText("Attached Resume")).click();
driver.findElement(By.partialLinkText("Attached Resume")).click();
driver.fineElement(By.xpath("//a[contains(text(),'Attached Resume')]")).click();

答案 2 :(得分:0)

我使用下面的Xpath尝试了它:

driver.findElement(By.xpath("//a[@href ='//my.naukri.com/Profile/view/subAction/ar?id=&altresid=#ar']")).click();

答案 3 :(得分:0)

以下是您的问题的答案:

以下是打开网址 <?php $servername = "example"; $username = "example1"; $password = "example2"; $dbname = "your_db_name"; // Specify your db-name here. $conn = new mysqli($servername,$username,$password,$dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; $sql = "Select Distinct subject from mobile_math_science_toc"; $result = mysqli_query($conn, $sql); // Checking if there are some records available. if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { echo "Subject " ,$row["subject"]; } } else { echo "0 results "; } mysqli_close($conn); ?> 的工作代码,通过有效凭据登录并点击 https://www.naukri.com/ 链接:

Attached Resume

如果这回答你的问题,请告诉我。