获得价值无法理解

编程入门 行业动态 更新时间:2024-10-24 19:16:17
本文介绍了获得价值无法理解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在编写一个selenium代码来执行以下操作。

I'm writing a selenium code to do the below thing.

  • 在文本框中输入值。
  • 选择下拉值。
  • 选择一个单选按钮。
  • 点击go按钮。
  • Enter value in text box.
  • Select the dropdown value.
  • Select a radio button.
  • Hit the go button.
  • 当我这样做时,我会得到一个结果列表,我想得到第一个结果块的标题。

    When I do this, I will get a list of results and I want to get the heading of the first result block.

    以下是我的代码。

    import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class Test1 { public static void main(String[] args) throws InterruptedException { WebDriver driver; System.setProperty("webdriver.gecko.driver", "C:\\Users\\home\\Downloads\\geckodriver.exe"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); driver = new FirefoxDriver(capabilities); driver.get("www2.chubb/us-en/find-agent-page.aspx"); driver.findElement(By.xpath(".//*[@id='tbAddress']")).sendKeys("60089"); driver.findElement(By.xpath(".//*[@id='cphHeroContent_drpDistanceMiles']")).sendKeys("2"); driver.findElement(By.xpath(".//*[@id='cphHeroContent_rdType_0']")).click(); driver.findElement(By.xpath(".//*[@id='cphHeroContent_btnSearch']")).click(); String title = driver.getTitle().toString(); System.out.println(title); Thread.sleep(10000L); String getHeadingTitle = driver.findElement(By.xpath(".//*[@id='chubbAgentData']/li/h2")).toString(); System.out.println(getHeadingTitle); } }

    在我的代码中,我是能够完成step1,2,3,我可以在我的控制台中获得标题名称。

    In my code, I'm able to get step1, 2, 3 done and I able to get the title name in my console.

    在尝试获取标题文本时,它给了我以下异常。

    It is giving me the below exception when trying to get the heading text.

    JavaScript错误: www2.chubb/us-en/find-agent-page.aspx ,第2行:SyntaxError:expected expression,got' <'

    JavaScript error: www2.chubb/us-en/find-agent-page.aspx, line 2: SyntaxError: expected expression, got '<'

    JavaScript警告: www2.chubb/_Global-Assets/js/jquery-webdriver.js ,第1行:使用// @表示sourceMappingURL编译指示已弃用。使用//#代替[[FirefoxDriver:firefox on XP (320d5e47-8575-4566-9622-d8275cf72ded)] - > xpath: .//* [@ id ='chubbAgentData '] / li / h2]

    JavaScript warning: www2.chubb/_Global-Assets/js/jquery-webdriver.js, line 1: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead [[FirefoxDriver: firefox on XP (320d5e47-8575-4566-9622-d8275cf72ded)] -> xpath: .//*[@id='chubbAgentData']/li/h2]

    请告诉我哪里出错了,我该如何解决这个问题。

    Please let me know where am I going wrong and how can I fix this.

    推荐答案

    你不应该使用 toString()方法 - 使用 getText():

    You should not be using toString() method - use getText():

    driver.findElement(By.xpath(".//*[@id='chubbAgentData']/li/h2")).getText();

    更多推荐

    获得价值无法理解

    本文发布于:2023-07-27 14:04:23,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1222758.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:价值

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!