Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have tried all ways possible to locate the bellow import file window elements from google sheets and yet haven't locate it. Here is the code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time
import pynput
from pynput.keyboard import Key, Controller
keyboard = Controller()
import os
import logging
import glob
#save chrome user data to chromedriver
options = webdriver.ChromeOptions()
options.add_argument("") #Path to your chrome profile
driver = webdriver.Chrome(executable_path="C:\\Program Files (x86)\\chromedriver.exe", chrome_options=options)
#open the google sheet in chrome
driver.get("https://docs.google.com/spreadsheets/d/")
wait3 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "docs-file-menu")))
#click on file menue
wait3 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "docs-file-menu")))
driver.find_element_by_id("docs-file-menu").click()
#click on import
wait3 = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, ":4q")))
driver.find_element_by_id(":4q").click()
Google Sheet import Window
The Element which you are looking for is in the iframe.
First, you have to switch to that iframe and then start searching for your element.
Related
How can I take screenshot of only relevant content of any webpage using Selenium and Python?
I want to take the screenshot of the marked content (specifications) in this photo instead of whole page
Example webpage link
Currently I'm taking screenshot of the whole page. Also I want avoid referencing any class or id while taking the screenshot. Please let me know if I can achieve this (if yes, HOW?) or have to change my requirements. If there is any workaround such as cropping the relevant content, please do share too. Thanks.
Chrome appears to be a bit temperamental when screenshotting - only takes what's visible on screen, so I would advise Firefox/geckodriver for these kind of jobs. The following will take a full screenshot of that element:
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options as Firefox_Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import time as t
firefox_options = Firefox_Options()
firefox_options.add_argument("--width=1280")
firefox_options.add_argument("--height=720")
# firefox_options.headless = True
driverService = Service('chromedriver/geckodriver')
browser = webdriver.Firefox(service=driverService, options=firefox_options)
actions = ActionChains(browser)
url = 'https://www.startech.com.bd/benq-gw2480-fhd-monitor'
browser.get(url)
elem = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//section[#id='specification']")))
elem.screenshot('fullspec.png')
print('screenshotted specs')
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 months ago.
Improve this question
I'm getting this error when I try to run my selenium test:
[9680:18428:0605/111414.227:ERROR:device_event_log_impl.cc(214)] [11:14:14.228] Bluetooth: bluetooth_adapter_winrt.cc:1074 Getting Default Adapter failed.
This is how my `conftest.py` file looks like:
Code
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = options, service=Service(ChromeDriverManager().install()))
Facebook = "https://facebook.com"
wait = WebDriverWait(driver, timeout=60)
#pytest.fixture
def set_up():
driver.maximize_window()
driver.get(Facebook)
As you can see I'm trying to make tests for Facebook using Google Chrome, but for some reason I get the mentioned error, does anyone know how to fix this
You can Suppress this error by using below.
As per the documentation in Selenium Chrome Driver: Resolve Error Messages Regarding Registry Keys and Experimental Options these error logs can be supressed by adding the argument:
excludeSwitches: ['enable-logging']
So your effective code block will be:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
I am unable to retrieve any search results in fbref.com when using either of send_keys and execute_script in selenium for python using chrome web driver
This is the code ive used so far:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import pandas as pd
import numpy as np
import csv
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
s=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.get("https://fbref.com/en/")
element = driver.find_element(by=By.CLASS_NAME, value="ac-hint")
action = ActionChains(driver)
element1= driver.find_element(by=By.CSS_SELECTOR, value=("input[type='search']"))
action.click(on_element=element1)
action.perform()
#element.send_keys("lionel messi")
#driver.execute_script("arguments[0].value='lionel messi'",element)
element2=driver.find_element(by=By.CSS_SELECTOR, value=("input[type='submit']"))
action.click(on_element=element2)
action.perform()```
The code is able to interact with the search button and the text is typed and the search button is clicked without any trouble but the search result is as follows:
which basically means that the search was invalid ,ive tried to search manually in the browser window opened by the driver and that gives me a successful result
You are doing your player name input in the wrong field, if you look closely at the html, there are 2 input fields for the search.
instead of the "ac-hint", use "ac-input":
element = driver.find_element(by=By.CLASS_NAME, value="ac-input")
The locator strategy you have used to identify the search field
doesn't identifies the desired element uniquely within the HTML DOM
Solution
To send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solution:
Code Block:
driver.get("https://fbref.com/en/")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='search'][placeholder='Enter Person, Team, Section, etc']"))).send_keys("lionel messi" + Keys.RETURN)
Note: You have to add the following imports :
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Browser Snapshot:
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I forgot my password and I wrote this code with Selenium to try to recover my pass, but I don't know how to continue.
The button new password doesn't work.
Can someone help me? I try different ways to continue but I don't know. Is any way to enter?
I am trying to remember my password using the function. Something like force brute. So, I dont know how to make a loop generating a new password, with the function, enter it in the box "Contraseña: " until it is correct
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import time
import os
import datetime
from datetime import datetime
from playsound import playsound
import smtplib, ssl
from random import sample
def password_generator(longitud):
abc_minusculas = "abcdefghijklmnopqrstuvwxyz"
abc_mayusculas = abc_minusculas.upper()
numeros = "0123456789"
secuencia = abc_minusculas + abc_mayusculas + numeros
password_union = sample(secuencia, longitud)
password_result = "".join(password_union)
return password_result
PATH = "C:\Program Files (x86)\Chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("http://siga.frba.utn.edu.ar/")
print(driver.title)
link = driver.find_element_by_id("page-try")
link.click()
time.sleep(1)
link = driver.find_element_by_xpath('//*[#id="menu-page-try"]/p[4]/a')
link.click()
time.sleep(1)
search = driver.find_element_by_name("form_email")
search.send_keys("35335")
search.send_keys(Keys.RETURN)
time.sleep(0.5)
1 The locator you used is not unique (there are two of them). So I replaced it with xpath locator //input[#name='form_email'].
2 You are using time.sleep everywhere. It may be slower then using Selenium's explicit/implicit wait and also it's very unstable
So, I added wait = WebDriverWait(driver, 30) to your code and applied explicit waits.
3 Also, I noticed that page-try id is not unique, so I replaced it with css selector. If you are using find_element..., not find_elements... then your locators have to be unique.
Solution
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import time
import os
import datetime
from datetime import datetime
import smtplib, ssl
from random import sample
PATH = '/snap/bin/chromium.chromedriver'
driver = webdriver.Chrome(executable_path=PATH)
driver.get("http://siga.frba.utn.edu.ar/")
print(driver.title)
wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#page-try"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Usuarios registrados')]"))).click()
search = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[#name='form_email']")))
search.send_keys("35335")
search.send_keys(Keys.RETURN)
To click Solicitar nueva contraseña button use this xpath: //a[contains(text(), 'Solicitar nueva contraseña')]
Try using the locators I provided as examples for other elements on your site. Use this as a reference https://www.w3schools.com/xml/xpath_intro.asp
I had this issue on 2 different systems, on first PC it went away after a reboot, on the other it had not gone away
Below is a portion of the code in question:
I masked some things on purpose
The edge browser is stuck on openign page with data;, shown in the address bar. It does not go beyond this.
I checked that Edge and Edgedriver are the same exact version, if it matters.
I cannot use Chrome or any other drivers for this project
Why doesn't selenium advance past the opening of the program?
I also have an error in CMD when it launches: [9704:11992:0305/080544.278:ERROR:storage_reserve.cc(164)] Failed to open file to mark as storage reserve: C:\Users**\AppData\Local\Temp\scoped_dir3468_1483298328\Default\Code Cache\js on selenium
How do I fix this?
# importing required package of webdriver
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.opera.options import Options
from selenium.webdriver.support.wait import WebDriverWait
import schedule
import time
from random import randint
def job():
while True:
# Instantiate the webdriver with the executable location of MS Edge
browser = webdriver.Edge(r"C:\Users\*****\Desktop\msedgedriver.exe")
sleep(2)
browser.maximize_window()
sleep(2)
browser.get('https://********/) #masked the name of website on purpose
try:
# Get the text box to insert Email using selector ID
myElem_1 = WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.ID, 'anti-myhub')))
sleep(3)
# Entering the email address
myElem_1.click()