0

Problem -

I've been trying to find the correct xpath for a element. I couldn't get the element in correct manner.

Observation -

I observed, It may be due to the element is located inside or under the frame component. Can anyone help me to interact with the element which is located under frame?

Question - How to interact on element inside frame?

Below I'm sharing html code, for better understanding.

<div class="login-block last">
    <form name="frm" action="authenticatorProcess.cgi" method="post" onsubmit="return validate_form(this)">
    <form name="frm" action="authenticatorProcess.cgi" method="post" onsubmit="return validate_form(this)">
    <table width="290" align="center">
    <tbody>
        <tr>
        <tr>
        <tr>
        <tr>
        <tr>
        <tr>
        <tr>
        <th align="right">
        <td align="left">
        <input id="rutClient" name="rutClient" size="15" onchange="Rut(document.frm.rutClient.value)" onblur="Rut(document.frm.rutClient.value)" type="text">
        </td>
    </tr>
    <tr>
    <tr>
    <tr>
    </tbody>
    </table>

<div class="login-block last">
<form name="frm" action="authenticatorProcess.cgi" method="post" onsubmit="return validate_form(this)">
<table width="290" align="center">
    <tbody>
        <tr>
        <tr>
        <tr>
        <tr>
        <tr>
        <tr>
        <tr>
        <th align="right">
        <td align="left">
    <input id="rutClient" name="rutClient" size="15" onchange="Rut(document.frm.rutClient.value)" onblur="Rut(document.frm.rutClient.value)" type="text">
    </td>
    </tr>
    <tr>
    <tr>
    <tr>
    </tbody>
    </table>

I tried with the following

by.xpath(//form[@name='frm']//input[@type='text'])//*[@id='rutClient']
//html/body/div[1]/form/table/tbody/tr[7]/td/input/by.id("rutClient")
4
  • What does "elementToBeSelected" mean in this context? I would have thought only checkboxes etc. could be selected, not text elements.
    – user246
    Commented Oct 18, 2016 at 17:11
  • If your element has id, why you insist on locating it by XPATH? Id > name > css > link text, I avoid XPATH like a plague. Commented Oct 18, 2016 at 17:33
  • i tried with the by.id but element is not found
    – josekimet
    Commented Oct 18, 2016 at 18:27
  • Voting to Reopen! Commented Oct 20, 2016 at 5:26

1 Answer 1

2

Well said Peter. Totally Agree for ID > Name > CSS > LinkText

@josekimet -

  • First ensure that element you are looking to perform action is visible

    your_element.isDisplayed();

  • If not visible then you need to add implicit wait until that element get visible on page

  • After that using ID, I guess you will able to interact with element

  • Modified: If you are interacting element which is in frame. You need to switch to that frame

  • Once you switch to targeted frame then only all the elements will be accessible with locators like id/name/css/xpath

    driver.switch_to.frame(driver.find_element_by_id('frame_id'));

  • Now you will be able to find element using 'id'

    driver.findElement(By.xpath("//*[@id='element_id']"));

4
  • i found that the item is inside a frame
    – josekimet
    Commented Oct 19, 2016 at 10:41
  • but i couldn't get the by id.. how i tell the driver to look into the frame?
    – josekimet
    Commented Oct 19, 2016 at 10:42
  • you can use xpath using more than one locator. ex - driver.findElement(By.xpath("//*[@id='element_id' and @name='actual_parameter_value']")); you can use name/class/css/type Commented Oct 19, 2016 at 11:00
  • updated my answer - it should work now. Pls check Commented Oct 19, 2016 at 11:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.