Selenium Webdriver: click on a switch that does not work

I have a code that clicks on a switch, first I used Chrome. Using the following code:

driver.findElement(By.id("radioButton1"))).click();

I got an error:

"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675). Other element would receive the click: ..."

After doing research, I changed the code to:

actions.moveToElement(driver.findElement(By.id("radioButton1"))).click().perform();

Now I am trying to use the Internet Explorer driver. But he does not click.

I tried the following:

driver.findElement(By.id("radioButton1")).sendKeys(Keys.ENTER);

actions.moveToElement(driver.findElement(By.id("radioButton1"))).click().perform();

((JavascriptExecutor) driver).executeScript("arguments[0].click()", driver.findElement(By.id("radioButton1")));

But no one is working. The first only focuses on the button, so I added another sendKeys, but it does not work. 2nd and 3rd, nothing happens.

Edit:

Adding an HTML fragment.

<input name="btn1" class="w-rdo-native" id="radioButton1" type="radio" value="value1" bh="RDOINP" isrefresh="false">
<label class="w-rdo w-rdo-dsize" bh="RDO"></label>

And when I click on the switch, the shortcut gets an additional property after the click.

<label class="w-rdo w-rdo-dsize" bh="RDO" AWMouseDown="true"></label>

Additional editing:

The set of buttons looks like this:

enter image description here

and, as stated earlier, one block of + label buttons has the following HTML structure:

<tr>
   <td>
      <div class="w-rdo-container">
          <input name="radioButtons" class="w-rdo-native" id="button1" type="radio" value="button1" bh="RDOINP" isrefresh="false">
          <label class="w-rdo w-rdo-dsize" bh="RDO">
          </label>
      </div>
  </td>
  <td class="sectionHead">Option 2
  </td>
</tr>

When a button is pressed, the corresponding label receives an additional attribute:

<label class="w-rdo w-rdo-dsize" bh="RDO" AWMouseDown="true"></label>

, AWMouseDown, , "" .

:

HTML. ( , , - , .)

<table border="0" cellpadding="0" cellspacing="0" class="a-cptp-tbl">
    <tbody>
        <tr>
            <td>
                <div class="w-rdo-container">
                    <input checked class="w-rdo-native" id="btn1" name="radioBtn" type="radio" value="btn1"><label class="w-rdo w-rdo-dsize"></label>
                </div>
            </td>
            <td class="sectionHead">Option 1</td>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>
                <div class="w-rdo-container">
                    <input class="w-rdo-native" id="btn2" name="radioBtn" type="radio" value="btn2"><label class="w-rdo w-rdo-dsize"></label>
                </div>
            </td>
            <td class="sectionHead">Option 2</td>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>
                <div class="w-rdo-container">
                    <input class="w-rdo-native" id="btn3" name="radioBtn" type="radio" value="btn3"><label class="w-rdo w-rdo-dsize"></label>
                </div>
            </td>
            <td class="sectionHead">Option 3</td>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>
                <div class="w-rdo-container">
                    <input class="w-rdo-native" id="btn4" name="radioBtn" type="radio" value="btn4"><label class="w-rdo w-rdo-dsize"></label>
                </div>
            </td>
            <td class="sectionHead">Option 4</td>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>
                <div class="w-rdo-container">
                    <input class="w-rdo-native" id="btn5" name="radioBtn" type="radio" value="btn5"><label class="w-rdo w-rdo-dsize"></label>
                </div>
            </td>
            <td class="sectionHead">Option 5</td>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>
                <div class="w-rdo-container">
                    <input class="w-rdo-native" id="btn6" name="radioBtn" type="radio" value="btn6"><label class="w-rdo w-rdo-dsize"></label>
                </div>
            </td>
            <td class="sectionHead">Option 6</td>
        </tr>
        <tr>
            <td></td>
        </tr>
    </tbody>
</table>
+4
8

JavaScript, :

WebElement radioBtn1 = driver.findElement(By.id("radioButton1"));
((JavascriptExecutor) driver).executeScript("arguments[0].checked = true;", radioBtn1);

QMetry Automation Framework, , , .

+1

, , get()?

List<WebElement> radioGrp = driver.findElements(By.name("xxxxxxxx"));
radioGrp.get(0).click();
0

ExplicitWait, ,

     WebElement element = driver.findElement(By.id("radioButton1"));
     WebDriverWait wait = new WebDriverWait(driver, 120);
     wait.until(ExpectedConditions.elementToBeClickable(element));

     element.click();

EDITED

IE. IE: ActiveX Controls

, -

  • "" > "" > "" - enter image description here

  • > ,

script , id

driver.findElement(By.id("button1")).click(); 

, . , - .

0

, . :

 public static IWebDriver driver;
    [Test]
    public void TestMethod1()
    {
        driver = new PhantomJSDriver();
        driver.Navigate().GoToUrl("file:///C:/Users/utripra/Desktop/test.html");
        driver.FindElement(By.Id("radioButton1")).Click();
0

, - <input> <label>, .. <div> class="w-rdo-container" <td>. , <td> <td>, Option 2 - .

class="w-rdo-container" , xpath html- id="button1"

driver.findElement(By.xpath("//div[input[@id='button1']]")).click(); // to click the div
// or
driver.findElement(By.xpath("//td[div[input[@id='button1']]]")).click(); // to click the td
0

2:

driver.findElement(By.xpath("//td[normalize-space(text())='Option 2']/preceding::input[1]")).click();
0

, cssSelector :

driver.findElement(By.cssSelector("table.a-cptp-tbl > tbody > tr:nth-child(" + checkBoxPosition + ") > td > div > input")).click();

:

public void selectOption(int positionOfCheckBox){
        By locator = By.cssSelector("table.a-cptp-tbl > tbody > tr:nth-child(" + positionOfCheckBox + ") > td > div > input");
        //wait for your element to be visible
        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
        //click element after it is visible/clickable
        driver.findElement(locator).click();
    }
0

Just add a Thread.sleep(5000);script for the radio above your radio button. For example, for example

     Thread.sleep(5000);
     driver.findElement(By.id("uniform-id_gender2")).click();

This works for me. :)

-1
source

Source: https://habr.com/ru/post/1666207/


All Articles