Java 根据您定义的问题陈述,请求的解决方案是“定位情感图标”。您可以修改该方法以任何方式查找问题。但问题的关键仍然是,你只能找到相对于“定位问题”的情感图标。不幸的是,到目前为止,我无法解决这个问题。我甚至尝试了不同的webdriver/版本,因为我在查找任何容

Java 根据您定义的问题陈述,请求的解决方案是“定位情感图标”。您可以修改该方法以任何方式查找问题。但问题的关键仍然是,你只能找到相对于“定位问题”的情感图标。不幸的是,到目前为止,我无法解决这个问题。我甚至尝试了不同的webdriver/版本,因为我在查找任何容,java,selenium,xpath,selenium-webdriver,selenium-firefoxdriver,Java,Selenium,Xpath,Selenium Webdriver,Selenium Firefoxdriver,根据您定义的问题陈述,请求的解决方案是“定位情感图标”。您可以修改该方法以任何方式查找问题。但问题的关键仍然是,你只能找到相对于“定位问题”的情感图标。不幸的是,到目前为止,我无法解决这个问题。我甚至尝试了不同的webdriver/版本,因为我在查找任何容器或元素时没有任何问题。不管怎样,如果有人愿意把手弄脏,我想做个测试。当然。在github上发布测试项目,或在linkedin/twitter上向我发送消息。有关我的SO个人资料页面的详细信息。 <form action="/assess


根据您定义的问题陈述,请求的解决方案是“定位情感图标”。您可以修改该方法以任何方式查找问题。但问题的关键仍然是,你只能找到相对于“定位问题”的情感图标。不幸的是,到目前为止,我无法解决这个问题。我甚至尝试了不同的webdriver/版本,因为我在查找任何容器或元素时没有任何问题。不管怎样,如果有人愿意把手弄脏,我想做个测试。当然。在github上发布测试项目,或在linkedin/twitter上向我发送消息。有关我的SO个人资料页面的详细信息。
<form action="/assessments/1290/questions" id="questionform" method="post">
  <div class="happiness-reaction__item animated fadeIn selected">
    I often get upset over minor issues.
    <div class="inputs">

      <input id="choice_14832" value="14832" name="Answers[0].Choices" data-scv-reaction-id="strongly-disagree1" spellcheck="true" type="radio">
      <label class="u" for="choice_14832">
        <i class="sc-strongly-disagree"></i>
      </label>

      <input id="choice_14833" value="14833" name="Answers[0].Choices" data-scv-reaction-id="slightly-disagree1" spellcheck="true" type="radio">
      <label class="u" for="choice_14833">
        <i class="sc-slightly-disagree"></i>
      </label>

      <input id="choice_14834" value="14834" name="Answers[0].Choices" data-scv-reaction-id="none1" spellcheck="true" type="radio">
      <label class="u" for="choice_14834">
        <i class="sc-none"></i>
      </label>

      <input id="choice_14835" value="14835" name="Answers[0].Choices" data-scv-reaction-id="slightly-agree1" spellcheck="true" type="radio">
      <label class="u" for="choice_14835">
        <i class="sc-slightly-agree"></i>
      </label>

      <input id="choice_14836" value="14836" name="Answers[0].Choices" data-scv-reaction-id="strongly-agree1" spellcheck="true" type="radio">
      <label class="u" for="choice_14836">
        <i class="sc-strongly-agree"></i>
      </label>
    </div>
  </div>
                 .....
WebElement button = driver.findElement(By.xpath(".//*[@id='questionform']/div[1]/div/label[1]/i"));
button.click();
//*[@data-scv-reaction-id='strongly-disagree1']
public void reactToQuestion(String question, String reaction) { // Get the question element // For eg. question = "I always complete all aspects of my work." By locQuestion = By.xpath("//*[text()='" + question + "']"); WebElement element = driver.findElement(locQuestion); // Get the parent 'div' container of the question WebElement container = element.findElement(".."); // Get reaction RELATIVELY to the question // reaction = 'strongly-disagree1', 'slightly-disagree1', etc. By locReaction = By.xpath(".//*[@class='inputs']/input[@data-scv-reaction-id=" + reaction + "]"); WebElement reaction = container.findElement(locReaction); reaction.click(); }
public static void selectChoice(String question, Choices choice)
{
    driver.findElement(By.xpath("//div[contains(@class,'happiness-reaction__item')][contains(.,'" + question + "')]//i[@class='" + choice.value() + "']")).click();
}
public enum Choices
{
    STRONGLYDISAGREE("sc-strongly-disagree"),
    SLIGHTLYDISAGREE("sc-slightly-disagree"),
    NONE("sc-none"),
    SLIGHTLYAGREE("sc-slightly-agree"),
    STRONGLYAGREE("sc-strongly-agree");

    private String value;

    Choices(String value)
    {
        this.value = value;
    }

    public String value()
    {
        return value;
    }
}
selectChoice("I often get upset over minor issues.", Choices.STRONGLYAGREE);
//form[@id='questionform']/div//input
//form[@id='questionform']/div[contains(@class, 'happiness-reaction')]//input
//form[@id='questionform']/div[contains(@class, 'happiness-reaction')]//input[@data-scv-reaction-id='strongly-disagree1']
//form[@id='questionform']/div[contains(@class, 'part_of_question_class')]//input[@data-scv-reaction-id='desired_answer_attr']
form#questionform>div input
form#questionform>div[class*=happiness-reaction] input
form#questionform>div[class*=happiness-reaction] input[data-scv-reaction-id='strongly-disagree1']