I'm trying to automate the Linkedin login page. But the I can not pass text in to its password filed. I check the password filed visibility by using webElement.isDsiplyed() and password field is disable. Password text field contain in a form. Thats mean It's not using javascript. I tried below methods.
01.
WebElement linkedinPassword = driver.findElement(By.xpath("//li[@class='password-input']//div/input"));
linkedinPassword.click();
linkedinPassword.sendKeys(new String[] { vars.get("LinkedinPassword") });
Error in the logs;
[org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'achini-ThinkPad-X1-Carbon-5th', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.13.0-45-generic', java.version: '1.8.0_171'
Driver info: driver.version: unknown
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.verifyCanInteractWithElement(HtmlUnitWebElement.java:283)
at org.openqa.selenium.htmlunit.HtmlUnitWebElement.sendKeys(HtmlUnitWebElement.java:327)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at bsh.Reflect.invokeMethod(Reflect.java:134)
at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
at bsh.Name.invokeMethod(Name.java:858)
at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
at bsh.BSHBlock.eval(BSHBlock.java:80)
at bsh.BSHBlock.eval(BSHBlock.java:46)
at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
at bsh.Interpreter.eval(Interpreter.java:645)
at bsh.Interpreter.eval(Interpreter.java:739)
at bsh.Interpreter.eval(Interpreter.java:728)
at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:78)
at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:222)
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:69)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:498)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:424)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:255)
at java.lang.Thread.run(Thread.java:748)][1]
Anybody have idea how to do the login in to Linkedin using selenium.
答案 0 :(得分:0)
我不知道您为什么要尝试在“密码”输入框中单击。我的代码建议是(使事情简单):
driver.manage()。timeouts()。implicitlywait(30,TimeUnit.SECONDS); driver.findElementByXpath(“ // li [@ class ='password-input'] // div / input”))。sendkeys(“ yourpassword”);
如果仍然无法识别,请检查您使用的Xpath以及是否能够从DOM中获取。
答案 1 :(得分:0)
要标识密码字段,可以使用以下解决方案之一:
css_selector
:
driver.find_element_by_css_selector("input.login-password#login-password").send_keys("Achini")
xpath
:
driver.find_element_by_xpath("//input[@class='login-password' and @id='login-password']").send_keys("Achini")
注意:在此解决方案中,我希望您已经诱使 Email or phone number
可以点击的 WebDriverWait 。因此,我在密码字段中删除了 WebDriverWait 。
答案 2 :(得分:0)
谢谢大家的支持。 因为我将硒与HTMUnit驱动程序一起使用,所以在禁用Java脚本支持后解决了问题。在自动引导网页中将发生此问题。
要禁用JS支持
public HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, false);
并再次启用它
driver.setJavascriptEnabled(true);
参考:https://newfivefour.com/java-selenium-bootstrap-htmlunit.html