使用不同的定位符定位WebElement(NoSuchElementException)

问题描述 投票:0回答:1

我在使用不同的定位器定位WebElement时遇到问题。在下面的html标记中,我尝试使用不同的定位符(例如WebElementlinkTextxpath)定位“撰写评论” classname,但仍然得到NoSuchElementException

-> url https://www.tripadvisor.in/-> search for Club Mahindra-> click on Club Mahindra-> click on write a review

    <a href="/UserReview-g641714-d1156207-Club_Mahindra_Madikeri_Coorg- 
    Madikeri_Kodagu_Coorg_Karnataka.html" target="_blank" class="ui_button 
    primary">Write a review</a>

使用的定位器

  • By.xpath("//*[@id="component_12"]/div/div[2]/div/div[2]/div/div[1]/a")
  • By.xpath("//a[@href='/UserReview-g641714-d1156207- Club_Mahindra_Madikeri_Coorg-Madikeri_Kodagu_Coorg_Karnataka.html']")
  • By.className("ui_button primary")
  • By.linkText("Write a review")

我真的很困惑。我在做什么错?

java eclipse selenium selenium-webdriver testng
1个回答
0
投票
//a[contains(text(),'Write a review')]
© www.soinside.com 2019 - 2024. All rights reserved.