Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98817

How to create unique, complex Xpath to find a textarea tag?

$
0
0

Recently I'm struggling in my job with an issue of creating a proper Xpath selector to get the content of the demanded text area. Here's the structure of my HTML document:

<div id="X115OutsideBorder" style="left: 59.1%; top: 855px; width: 14.6%; height: 22px; position: absolute;">
  <div class="CheckBox ltr mandatoryFieldStyle " id="X115Border">
    <div class="xEdit FormatInputReadonly" id="X115Edit">
      <div style="display: inline-block; direction: ltr;">
       <label disabled="" class="xCheckboxIcon" id="X115Icon" for="X115"></label>
       <input name="instance/CUST.risk.major.inc" tabindex="-32768" disabled="" 
        id="X115" onclick="handleOnClick(this, event);" 
        onfocus="handleOnFocus(this, event);" onblur="handleOnBlur(this, event); 
        applyToSameControl(this);" onchange="handleOnChange(this, event);" 
        type="checkbox" readonly="" value="true" datachangeevent="3034" dvdvar="" 
        buttonid="" sctype="CheckBox" ref="instance/CUST.risk.major.inc">
      </div>
    <span class="xCheckboxLabelSpan FormatLabel " id="X115LabelSpan">
      <label class="xCheckboxLabel" id="X115Label" for="X115" enabledstyle="&#10;    
       color:&#10;    #000000;&#10;  ">Risk to Major Incident?</label>
    </span>
   </div>
 </div>
</div>
<input id="X117" type="hidden" value="0" dvdvar="instance/CUST.interface.error">
<span class="Label" id="X119" style="left: 0%; top: 885px; width: 15.1%; height: 22px; text-align: right; position: absolute;" type="label">
   <label id="X120_Label" for="X120">Additional Information</label>
</span>
<div class="MultiText" id="X120Border" style="left: 16%; top: 885px; width: 71.5%; height: 187px; position: absolute;">
   <div class=" mandatoryFieldStyle xEdit xTextArea" id="X120Edit" style="height: 187px;">
     <textarea name="instance/Additional.information" tabindex="-32768" id="X120" 
     style="height: 185px;" onkeyup="&#10;    lockFormOnValueChange(this);&#10;  " 
     onclick="handleOnClick(this, event);" onfocus="handleOnFocus(this, event);" 
     onblur="handleOnBlur(this, event); applyToSameControl(this);" 
     onchange="handleOnChange(this, event);" rows="4" cols="81" 
     dvdvar="instance/Additional.information" buttonid="" sctype="MultiText"> 
     </textarea>
   </div>
</div>

So I created a class in Java with usage of a Selenium framework, looking as follows:

        Thread.sleep(5000);
        WebDriverWait wait = new WebDriverWait(driver, 15);
        WebElement additionalInfoElement = wait.until
(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='sm-clpsSectionCnt ie cntExpanded']
//div[@class='MultiText']//div[@class=' mandatoryFieldStyle xEdit xTextArea'] //textarea[contains(@id,'X120')]")));
        driver.findElement(By.xpath("//div[@class='sm-clpsSectionCnt ie cntExpanded'] //div[@class='MultiText']//div[@class=' mandatoryFieldStyle xEdit xTextArea']
//textarea[contains(@id, 'X120')]"));
        Thread.sleep(3000);
        additionalInfoElement.click();
        String additionalInfoContent = additionalInfoElement.getText();
        driver.switchTo().defaultContent();

        Map<String, String> assigneesToKeywords = new HashMap<>();
        assigneesToKeywords.put("ee57977","Please select the affected Process / Application::SSR");
        assigneesToKeywords.put("c308042","Please select the affected Process / Application::SSR1");
        assigneesToKeywords.put("p853780","Please select the affected Process / Application::MMSR");
        assigneesToKeywords.put("c323607","Please select the affected Process / Application::Reporting");
        assigneesToKeywords.put("c152236","Please select the affected Process / Application::BOI");
        assigneesToKeywords.put("ex73629","K3, K4");
        assigneesToKeywords.put("C321274","Please select the affected Process / Application::CPR");
        assigneesToKeywords.put("X","Please select the affected Process / Application::FOBO");
        assigneesToKeywords.put("c325285","Please select the affected Process / Application::T-RECS");

        for (Map.Entry<String,String> entry : assigneesToKeywords.entrySet()){
            if (entry.getValue().contains(additionalInfoContent)){
                chosenAssignee=entry.getKey();
            }else
                chosenAssignee="XXXX";
        }

        return chosenAssignee;
    }

What I'm trying to do right now, is to get the content of the text area named "Additional Info" and compare it against the values of the map "assigneesToKeywords". However, Xpath which I created doesn't work and I ran out of ideas how to fix it... I still get the following error: "Expected condition failed: waiting for visibility of element located by By.xpath: ..."

So far I was trying to increase the amount of a time-out, but it didn't work. I guess it's all about the proper construction of an Xpath.

Any ideas of what I'm doing wrong? Thanks a lot in advance guys!

Best regards, Mateusz.


Viewing all articles
Browse latest Browse all 98817

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>