Selenium (Chrome webdriver.exe 105) confusing By.NAME, By.CLASS_NAME with By.CSS_SELECTOR - selenium-chromedriver

I am trying to authenticate with my Google account using Selenium. It's frustrating because I've done this before with Selenium, but none of the selectable elements are working properly.
The driver.page_source is slightly different from what Chrome renders in the dev tools' element inspector
The versions of the webdriver.exe and Chrome are the same
I'm running Python 3.8 on Windows 10
I used pip install selenium as the installation method.
Error when I run my script: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"#password > div.aCsJod.oJeWuf"}. In another case, I include the name="password" element in tripe quotes; yet, I still get the error, which states the method is "css selector", and it should be "name".
Attempts that result in the same error:
web_driver.find_element(By.NAME, value='''password''').send_keys('''sklksdflsjdf''')
web_driver.find_element(By.CLASS_NAME, value='''whsOnd zHQkBf''').send_keys('''sklksdflsjdf''')
web_driver.find_element(By.CSS_SELECTOR, value='''#password > div.aCsJod.oJeWuf > div > div.Xb9hP > input''').send_keys('''sklksdflsjdf''')
web_driver.find_element(By.XPATH, value='''//*[#id="password"]/div[1]/div/div[1]/input''').send_keys('''sklksdflsjdf''') (note: the error is the same but this does say "xpath" instead of "css selector", but the xpath is copied and pasted from Chrome dev tools)
Replaced the By object with by="class" or by="name", etc., which all result in the same error
If you have any questions, do not hesitate to ask in a comment. Otherwise, please help me with your ideas on how to get selenium to cooperate with the elements which I can clearly see in the driver.page_source.
Thank you!

Related

Selenium login to page with python 3.6 can't find element by name

Today I tried to write a code to make a bot for ytpals.com webpage.
I am using python selenium library.
What I am trying to do first is to login to page with my youtube channel ID.
But I was unsucessfull to find element 'channelid' whatever I do.
Adding to this this, page sometimes doesn't load fully...
Btw it worked for me with other pages to find an input form, but this page... I can't understand.
Maybe someone has better understanding than me and know how to log in in this page?
My simple code:
import time
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.ytpals.com/')
search = browser.find_element_by_name('channelid')
search.send_keys("testchannel")
time.sleep(5) # sleep for 5 seconds so you can see the results
browser.quit()
So I found a solution to my problem.
I downloaded SELENIUM IDE, and I can use it as a debugger, such a great tool!
if someone will need it, grab a link:
https://www.seleniumhq.org/docs/02_selenium_ide.jsp

How to locate a web element using webdriver:

How can we locate the web element whose html is:
<div class="wgt dashlet-pane-flowing vbox h-stretch" style="flex: 8 8 0%;">
I have tried following:
driver.findElement(By.cssSelector(".wgt.dashlet-pane-flowing.vbox.h-stretch"));
driver.findElement(By.xpath("//div[#class='wgt dashlet-pane-flowing vbox h-stretch']"));
but it is failed with error unable to locate web element.
Any help will be great..
Thanks in advance.
Target div might be generated dynamically, so you can try to wait for its appearance in DOM:
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[#class='wgt dashlet-pane-flowing vbox h-stretch']")));
There are couple of reason you will get this error.
Element is in different frame (which I don't think is the case)
It's not loaded properly while you are trying to find out (which might be the case). Please read about explicit waits and it will resolve the issue. I don't like giving the direct answer but someone here will. :)
Your xpath is wrong. You can check that with firebug and xpather plugin of firefox.
You have landed on the wrong page (you can check that visually)
If everything is good and still you are not able to find element, try below xpath
//div[contains(#style,'flex: 8 8 0%')]"

Is it possible to use Watir-Webdriver to interact with Polymer?

I just updated my Chrome browser (Version 50.0.2661.75) and have found that the chrome://downloads page has changed such that my automated tests can no longer interact with it. Previously, I had been using Watir-Webdriver to clear the downloads page, delete files from my machine, etc, without too much difficulty.
It looks like Google is using Polymer on this page, and
there are new (to me) elements like paper-button that Watir-Webdriver doesn't recognize
even browser.img(:id, 'file-icon').present? returns false when I
can clearly see that the image is on the page.
Is automating a page made with Polymer (specifically the chrome://downloads page) a lost cause until changes are made to Watir-Webdriver, or is there a solution to this problem?
Given that the download items are accessible in Javascript and that Watir allows Javascript execution (as #titusfortner pointed out), it's possible to automate the new Downloads page with Watir.
Note the shadow root elements (aka "local DOM" in Polymer) can be queried with $$.
Here's an example Javascript that logs the icon presence and filename of each download item and removes the items from the list. Copy and paste the snippet into Chrome's console to test (verified in Chrome 49.0.2623.112 on OS X El Capitan).
(function() {
var items = document
.querySelector('downloads-manager')
.$$('iron-list')
.querySelectorAll('downloads-item');
Array.from(items).forEach(item => {
let hasIcon = typeof item.$$('#file-icon') !== 'undefined';
console.log('hasIcon', hasIcon);
let filename = item.$$('#file-link').textContent;
console.log('filename', filename);
item.$.remove.click();
});
})();
UPDATE: I verified the Javascript with Watir-Webdriver in OS X (with ChromeDriver 2.21). It works the same as in the console for me (i.e., I see the console logs, and the download items are removed). Here are the steps to reproduce:
Run the following commands in a new irb shell (copy+paste):
require 'watir-webdriver'
b = Watir::Browser.new :chrome
In the newly opened Chrome window, download several files to create some download items, and then open the Downloads tab.
Run the following commands in the irb shell (copy+paste):
script = "(function() {
var items = document
.querySelector('downloads-manager')
.$$('iron-list')
.querySelectorAll('downloads-item');
Array.from(items).forEach(item => {
let hasIcon = typeof item.$$('#file-icon') !== 'undefined';
console.log('hasIcon', hasIcon);
let filename = item.$$('#file-link').textContent;
console.log('filename', filename);
item.$.remove.click();
});
})();"
b.execute_script(script)
Observe the Downloads tab no longer contains download items.
Open the Chrome console from the Downloads tab.
Observe the console shows several lines of hasIcon true and the filenames of the downloaded items.
Looks like Google put the elements inside the Shadow-Dom, which isn't supported by Selenium/Watir/WebDriver spec (yet). There might a way to obtain the element via javascript (browser.execute_script(<...>)), but it is experimental at best still.
Attempting to automated a Polymer page, I found I was able to access the web elements by asking Polymer to use the shady dom by adding ?dom=shady in the URL. Like in the example on this page https://www.polymer-project.org/1.0/docs/devguide/settings:
http://example.com/test-app/index.html?dom=shady
Adding the dom parameter to request Polymer to use the shady dom may be worth a try.

AngularJs project doesnt run in ie-8 and onward?

Please help how to run angularjs project in ie-8 and onward?
we have venueSvc angular service that are working fine in other browsers(chrome,firefox,opera etc) but not working in ie-8 and onward.
it is giving the following error.
Unknown provider: venueSvcProvider <- venueSvc
Looks like your service is not being included properly. Ie8 has some issues with directives being used as elements without being specified, however it should work in general. That error looks as though the program cannot find the provider, so make sure it exists in your source.

Debugging caja issues in google apps script [Google issue 2325]

I have a script that worked fine last week, but no longer works today.
I have tried to reproduce the problem in a simple example to share here but can't reproduce my problem in smaller scripts.
The script creates a html interface (using HtmlService.createTemplateFromFile) and contains an OL to which the li items are added using javascript on the client side (from an array.)
The li items are made selecteable using jquery's $("olid").selectable() ;
When I run this script the chrome console says
Domado: HTMLOListElement is not tamed; its specific properties/methods will not be available on <ol>. es53-taming-frame.opt.js:409
Domado: HTMLLIElement is not tamed; its specific properties/methods will not be available on <li>.
When I try to click the li items they are not selected. Instead I get the following error in the javascript console:
Cannot read property nodeType_v___ of undefined 2462517803-maestro_htmlapp_bin_maestro_htmlapp.js:39
lk 2462517803-maestro_htmlapp_bin_maestro_htmlapp.js:39
applyFunction es53-taming-frame.opt.js:1696
(anonymous function) es53-taming-frame.opt.js:1522
fn.i___ es53-taming-frame.opt.js:96
applyFeralFunction es53-taming-frame.opt.js:1507
applyFeralFunction es53-taming-frame.opt.js:1535
fn.i___ es53-taming-frame.opt.js:96
t$_var es53-taming-frame.opt.js:1571
Object.m___ es53-taming-frame.opt.js:404
plugin_dispatchEvent es53-taming-frame.opt.js:1472
fn.i___ es53-taming-frame.opt.js:96
wrapper
How can I start debugging this? Can I provide the project id to someone from google to see what's going on?
Hopefully someone will come along and explain this issue. Until then you could go at google caja playground (http://caja.appspot.com/) and see if your code works with the latest version of caja. I beleive that the gas version of caja is about 3 weeks behind from the latest.
The problem can now be worked around by using setSandboxMode(HtmlService.SandboxMode.IFRAME);
and as such disabling caja on your project.