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")

closed as unclear what you're asking by Yu Zhang, IAmMilinPatel, NarendraC, Kate Paulk, Paul Muir Oct 19 '16 at 13:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • What does "elementToBeSelected" mean in this context? I would have thought only checkboxes etc. could be selected, not text elements. – user246 Oct 18 '16 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. – Peter M. - stands for Monica Oct 18 '16 at 17:33
  • i tried with the by.id but element is not found – josekimet Oct 18 '16 at 18:27
  • Voting to Reopen! – NarendraC Oct 20 '16 at 5:26
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']"));

  • i found that the item is inside a frame – josekimet Oct 19 '16 at 10:41
  • but i couldn't get the by id.. how i tell the driver to look into the frame? – josekimet Oct 19 '16 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 – NarendraC Oct 19 '16 at 11:00
  • updated my answer - it should work now. Pls check – NarendraC Oct 19 '16 at 11:56

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