Selenium Web 드라이버 및 Java.요소(x, y)는 점(x, y)에서 클릭할 수 없습니다.다른 요소는 클릭을 받습니다.
명시적 대기를 사용했는데 경고가 있습니다.
org.openqa.selenium.WebDriverException:점(36, 72)에서 요소를 클릭할 수 없습니다.다른 요소는 클릭을 받습니다.명령어 지속시간 또는 타임아웃: 393 밀리초
사용하는 경우Thread.sleep(2000)
저는 아무런 경고도 받지 않았습니다.
@Test(dataProvider = "menuData")
public void Main(String btnMenu, String TitleResultPage, String Text) throws InterruptedException {
WebDriverWait wait = new WebDriverWait(driver, 10);
driver.findElement(By.id("navigationPageButton")).click();
try {
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(btnMenu)));
} catch (Exception e) {
System.out.println("Oh");
}
driver.findElement(By.cssSelector(btnMenu)).click();
Assert.assertEquals(driver.findElement(By.cssSelector(TitleResultPage)).getText(), Text);
}
WebDriverException:점(x, y)에서 요소를 클릭할 수 없습니다.
이것은 전형적인 org.openqa.selenium 입니다.java.lang을 확장하다WebDriverExceptionRuntime Exception 입니다.
이 예외의 필드는 다음과 같습니다.
- BASE_SUPPORT_URL:
protected static final java.lang.String BASE_SUPPORT_URL
- DRIVERIVER_INFO:
public static final java.lang.String DRIVER_INFO
- 세션 ID:
public static final java.lang.String SESSION_ID
각각의 사용 예에 대해서는, 이 에러에 의해서 모든 것이 에러집니다.
WebDriverException: Element is not clickable at point (x, y). Other element would receive the click
코드 블록에서 정의되어 있는 것은 명확합니다.wait
~하듯이WebDriverWait wait = new WebDriverWait(driver, 10);
하지만 당신은 전화하고 있다.click()
앞의 요소에 대한 메서드ExplicitWait
에서와 같이 기능하다until(ExpectedConditions.elementToBeClickable)
.
솔루션
에러Element is not clickable at point (x, y)
다른 요인에서 발생할 수 있습니다.이러한 문제는, 다음의 몇개의 순서로 해결할 수 있습니다.
1. JavaScript 또는 AJAX 호출로 인해 요소가 클릭되지 않음
사용해보십시오.Actions
클래스:
WebElement element = driver.findElement(By.id("navigationPageButton"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
2. Viewport에 없는 요소가 클릭되지 않음
를 사용하여 요소를 Viewport 내에 가져옵니다.
WebElement myelement = driver.findElement(By.id("navigationPageButton"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement);
3. 요소를 클릭하기 전에 페이지가 새로 고쳐지고 있습니다.
이 경우 포인트4에서 설명한 바와 같이 ExplicitWait, 즉 WebDriverWait를 유도합니다.
4. 요소가 DOM에 있지만 클릭할 수 없습니다.
이 경우 ExplicitWait를 유도합니다.ExpectedConditions
로 설정하다.elementToBeClickable
클릭 가능한 요소:
WebDriverWait wait2 = new WebDriverWait(driver, 10);
wait2.until(ExpectedConditions.elementToBeClickable(By.id("navigationPageButton")));
5. 요소가 존재하지만 임시 오버레이가 있습니다.
이 경우 Overlay가 보이지 않도록 로 설정하여 유도합니다.
WebDriverWait wait3 = new WebDriverWait(driver, 10);
wait3.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("ele_to_inv")));
6. 요소가 존재하지만 영구 오버레이가 있습니다.
사용하다JavascriptExecutor
클릭을 요소에 직접 보냅니다.
WebElement ele = driver.findElement(By.xpath("element_xpath"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
Javascript와 함께 사용해야 하는 경우
인수 [0.click()]를 사용하여 클릭 조작을 시뮬레이트할 수 있습니다.
var element = element(by.linkText('webdriverjs'));
browser.executeScript("arguments[0].click()",element);
일부 요소(또는 오버레이는 상관 없음)를 클릭하려고 할 때 이 오류가 발생했지만 다른 응답은 작동하지 않았습니다.를 사용하여 수정했습니다.elementFromPoint
Selenium이 대신 클릭하기를 원하는 요소를 찾기 위한 DOM API:
element_i_care_about = something()
loc = element_i_care_about.location
element_to_click = driver.execute_script(
"return document.elementFromPoint(arguments[0], arguments[1]);",
loc['x'],
loc['y'])
element_to_click.click()
또, 페이지의 요소 위에 있는 요소가 애니메이션으로 확장하거나 축소하는 등, 요소가 이동하는 상황도 있었습니다.이 경우 이 Expected Condition 클래스가 도움이 되었습니다.클릭할 요소가 아닌 애니메이션 요소를 제공합니다.이 버전은 jQuery 애니메이션에서만 작동합니다.
class elements_not_to_be_animated(object):
def __init__(self, locator):
self.locator = locator
def __call__(self, driver):
try:
elements = EC._find_elements(driver, self.locator)
# :animated is an artificial jQuery selector for things that are
# currently animated by jQuery.
return driver.execute_script(
'return !jQuery(arguments[0]).filter(":animated").length;',
elements)
except StaleElementReferenceException:
return False
시도해 보세요
WebElement navigationPageButton = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("navigationPageButton")));
navigationPageButton.click();
예외에서 언급된 포인트별로 페이지를 스크롤하는 것이 나에게 효과가 있었다.다음은 코드 스니펫입니다.
$wd_host = 'http://localhost:4444/wd/hub';
$capabilities =
[
\WebDriverCapabilityType::BROWSER_NAME => 'chrome',
\WebDriverCapabilityType::PROXY => [
'proxyType' => 'manual',
'httpProxy' => PROXY_DOMAIN.':'.PROXY_PORT,
'sslProxy' => PROXY_DOMAIN.':'.PROXY_PORT,
'noProxy' => PROXY_EXCEPTION // to run locally
],
];
$webDriver = \RemoteWebDriver::create($wd_host, $capabilities, 250000, 250000);
...........
...........
// Wait for 3 seconds
$webDriver->wait(3);
// Scrolls the page vertically by 70 pixels
$webDriver->executeScript("window.scrollTo(0, 70);");
메모: Facebook php webdriver를 사용합니다.
요소를 클릭할 수 없고 오버레이 문제가 발생할 경우 인수[0].클릭()을 사용합니다.
WebElement ele = driver.findElement(By.xpath("//div[@class='input-group-btn']/input"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
가장 좋은 해결책은 클릭 기능을 재정의하는 것입니다.
public void _click(WebElement element){
boolean flag = false;
while(true) {
try{
element.click();
flag=true;
}
catch (Exception e){
flag = false;
}
if(flag)
{
try{
element.click();
}
catch (Exception e){
System.out.printf("Element: " +element+ " has beed clicked, Selenium exception triggered: " + e.getMessage());
}
break;
}
}
}
에서는 C#의 확인에 .RadioButton
그리고 이것은 나에게 효과가 있었다.
driver.ExecuteJavaScript("arguments[0].checked=true", radio);
아래 코드로 시도 가능
WebDriverWait wait = new WebDriverWait(driver, 30);
Pass other element는 다음과 같습니다.<a class="navbar-brand" href="#"></a>
boolean invisiable = wait.until(ExpectedConditions
.invisibilityOfElementLocated(By.xpath("//div[@class='navbar-brand']")));
아래 그림과 같이 클릭 가능한 버튼 ID 전달
if (invisiable) {
WebElement ele = driver.findElement(By.xpath("//div[@id='button']");
ele.click();
}
언급URL : https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at-point-x-y-other-elem
'programing' 카테고리의 다른 글
하나의 캐치 블록에서 여러 예외 유형 포착 (0) | 2023.01.25 |
---|---|
JavaScript로 리다이렉트하려면 어떻게 해야 하나요? (0) | 2023.01.25 |
MariaDB - 청구서 번호 - 매년 0으로 돌아가기 (0) | 2023.01.25 |
왜 PHP에서 sprintf 함수를 사용하는가? (0) | 2023.01.25 |
PHP의 self::$bar와 static:$bar의 차이점은 무엇입니까? (0) | 2023.01.25 |