Selenium and Chromedriver - element not interactable

Viewed 500

I've been working with Selenium for a few weeks now. This script was working fine until the website owner recently updated the code, and now my logging into the website will no longer work.

Chrome Drivers and Selenium have been updated, it's an element that I can't seem to get to become intractable.

I've tried adding:

$seleniumDriver.Manage().Timeouts().ImplicitlyWait((New-TimeSpan -Seconds 5))

That didn't work.

I've also tried changing the code from

$ChromeDriver.FindElementXPath("//*[@id='email']").Click 

to

$ChromeDriver.FindElement("email_username"").Click

That also didn't work.

Also, adding a Start-Sleep -seconds 15 also didn't help.

There must be another way to get this username and password box clickable. Would appreciate any help. This is what I have so far.


$workingPath = 'C:\selenium'

if (($env:Path -split ';') -notcontains $workingPath) {
    $env:Path += ";$workingPath"
}

Add-Type -Path "$($workingPath)\WebDriver.dll"
Add-Type -Path "$($workingPath)\WebDriver.Support.dll"

$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver

# Launch a browser and go to URL
$ChromeDriver.Navigate().GoToURL("https://fund.traderscentral.com/overview")

# Enter the username in the Username box
$ChromeDriver.FindElementXPath("//*[@id='email']").Click

$ChromeDriver.FindElementByXPath('//*[@id="email"]').SendKeys('b0rken@gmail.com')

# Enter the password in the Password box
$ChromeDriver.FindElementByXPath('//input[@name="password"]').SendKeys('12345678')

# Click on the Login button
$ChromeDriver.FindElementByXPath("//button[@type='submit']").Click();

# Cleanup
$ChromeDriver.Close()
$ChromeDriver.Quit()
1 Answers

i am afraid that some bugs in selenium doesnt bring the solution at your problem:

it seems that the input field was not seen inside a div...

i have found a solution in c# by using Actions, i am not expert in powershell but i suppose Actions exist in powershell, C# and powershell could use same library:

this is my solution in C#: i just send keys with Actions, the first tab goes to the email field and i dont know why but i have to write all sendkeys in one line, hope that could help you:

Actions actions = new Actions(driver);
actions.SendKeys(Keys.Tab).SendKeys("b0rken@gmail.com").SendKeys(Keys.Tab).SendKeys("12345678").Perform(); 

Actions belongs to OpenQA.Selenium.Interactions

in powershell (not tested)

workingPath = 'C:\selenium'

if (($env:Path -split ';') -notcontains $workingPath) {
    $env:Path += ";$workingPath"
}

Add-Type -Path "$($workingPath)\WebDriver.dll"
Add-Type -Path "$($workingPath)\WebDriver.Support.dll"

$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver

# Launch a browser and go to URL
$ChromeDriver.Navigate().GoToURL("https://fund.traderscentral.com/overview")

#modif
# here 10sec adjust your wait time
[OpenQA.Selenium.Support.UI.WebDriverWait]$wait = New-Object OpenQA.Selenium.Support.UI.WebDriverWait ($ChromeDriver,[System.TimeSpan]::FromSeconds(10))
$wait.PollingInterval = 100

[void]$wait.Until([OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists([OpenQA.Selenium.By]::Id('email')))

[OpenQA.Selenium.Interactions.Actions]$actions = New-Object OpenQA.Selenium.Interactions.Actions ($ChromeDriver)
$actions.SendKeys([OpenQA.Selenium.Keys]::Tab).SendKeys("b0rken@gmail.com").SendKeys([OpenQA.Selenium.Keys]::Tab).SendKeys("12345678").Perform()

i have seen some adding build(), dunno the difference but you could test:

$actions.SendKeys([OpenQA.Selenium.Keys]::Tab).SendKeys("b0rken@gmail.com").SendKeys([OpenQA.Selenium.Keys]::Tab).SendKeys("12345678").Build().Perform()
Related