Google 검색 편집 상자에서 데이터를 가져오고 인쇄하려고 시도했지만 InvalidElementStateException이 발생했습니다.

샨 타누 난단

Google 검색 편집 상자에 단어를 쓰고 모든 관련 목록 항목을 캡처하여 표시하려고합니다. 하지만 그렇게하는 동안 예외가 발생했습니다. org.openqa.selenium.InvalidElementStateException : 요소가 비활성화되어 작업에 사용할 수 없습니다. 나는 동일한 예외 관련 질문을 겪었고 그들에 따라 내 코드를 변경했지만 아무도 도움이되지 않았습니다.

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

public class AutoIt {
 public static void main(String[] args){
  WebDriver window;
  FirefoxProfile profile = new FirefoxProfile();
  profile.setEnableNativeEvents(false);
  window = new FirefoxDriver(profile);
try{
window.get("https://www.google.co.in/");
window.manage().window().maximize();
window.findElement(By.id("gs_htif0")).sendKeys("Shantanu Nandan");
window.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
List<WebElement> list=window.findElements(By.xpath("//td[@style='width: 100%;']/span"));
window.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
for(WebElement data:list){
    System.out.println(data.getAttribute("value"));
 }//for
}//try
catch(Exception e){
System.out.println("Got a exception");
    e.printStackTrace();
    window.close();
}//catch
finally{
    System.out.println("Finally Block Executed ....");
    window.close();
    window.quit();
}//finally
  }//main
}//class

이 코드에 대해 얻은 예외

org.openqa.selenium.InvalidElementStateException: Element is disabled and so may not be used for actions
Command duration or timeout: 47 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'omega-d52b83806', ip: '10.0.0.4', os.name: 'Windows XP', os.arch:     'x86', os.version: '5.1', java.version: '1.7.0_45'
Session ID: d29ef567-95a8-47ce-bf84-c510cbb2756d
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true,     cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true,   browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=29.0.1}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193)
at      org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:268)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:89)
at AutoIt.main(AutoIt.java:21)
  Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Element is disabled and so may not be used for actions
  Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
  System info: host: 'omega-d52b83806', ip: '10.0.0.4', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_45'
Driver info: driver.version: unknown
at <anonymous class>.fxdriver.preconditions.enabled(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/[email protected]/components/command_processor.js:8185)
at <anonymous class>.DelayedCommand.prototype.checkPreconditions_(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/[email protected]/components/command_processor.js:10814)
at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/[email protected]/components/command_processor.js:10831)
at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/[email protected]/components/command_processor.js:10836)
at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/DOCUME~1/OMEGA/LOCALS~1/Temp/anonymous7567378475668954944webdriver-profile/extensions/[email protected]/components/command_processor.js:10778)
Finally Block Executed ....
사용자 3371491

잘못된 요소를 선택했습니다.

검색 텍스트 상자에 아래 항목을 사용하십시오.

wb=window.findElement(By.name("q"));

출력 제안을 얻으려면 아래를 사용하십시오.

List<WebElement> list = window.findElements(By.className("gsq_a"));

목록에서 값을 가져 오려면 getAttribute () 대신 getText () 메소드를 사용하십시오.

for (WebElement data : list) {
System.out.println(data.getText());
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관