here is my code
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium import webdriver
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.common.keys import Keys
import random
results = []
with open("al.txt") as inputfile:
for line in inputfile:
results.extend(line.strip().split(','))
x = random.choice(results)
driver = webdriver.Firefox()
while True:
driver.get(x)
element = driver.find_element_by_id("vB_Editor_QR_textarea")
driver.implicitly_wait(10)
element.send_keys("example")
driver.implicitly_wait(60)
driver.close()
i get
IndentationError: unexpected indent
PS C:\Users\asus\temp> python clickex1.py
File "clickex1.py", line 24
driver.implicitly_wait(60)
is it possible that selenium is installed wrong so python doesn't read the library?
the other lines are working perfectly fine. i need some help with this im new in using selenium and also python,
the script needs to go to the random websites in al.txt and post something in the designated area
Related
First off - no experience with Python, Sublime Text or Selenium - please be kind..
I am having an issue building a scraper in Python - using Sublime text, Selenium and Chrome. I have updated to the latest Python, Pip and downloaded the correct Chrome Driver. The webpage pops up fine, but get errors.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
#from selenium.webdriver.common.ui import WebDriverWait - commented out due to error
#from selenium.webdriver.common import expected_conditions as EC - commented out due to error
import time
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
driver.get ("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
print(driver.find_element(by=By.CLASS_NAME, value='ng-tns-c210-4 text-promo-1').text)***
wait = WebDriverWait(driver, 20)
driver.get("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
elem=wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.ng-tns-c210-4.text-promo-1')))
print(elem.text)
Your class name is actually multiple class names so using css selector.
Outputs:
$80.99
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
I am new to python and selenium. Trying to automate download of files from the dropdown menu on the below link for the first time. The code gets stuck after page loads i.e the drop down does not work and gives me an error. Sorry if my code looks clunky. Any help is appreciated.
Thanks
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
import time
s=Service("C:\\python\\chromedriver.exe")
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get('http://www.amfiindia.com/research-information/aum-data/classified-average-aum')
#monthname=driver.find_element(By.XPATH,"//*[#id='AaumDate']")
monthdd=Select(monthname)
monthdd.select_by_value('01-Jan-22')
time.sleep(3)
typename=driver.find_element(By.XPATH,"//*[#id='AumType']")
typedd=Select(typename)
typedd.select_by_visible_text('Scheme category wise')
time.sleep(3)
mfname=driver.find_element(By.XPATH,"//*[#id='AumMFName']")
mfdd=Select(mfname)
mfdd.select_by_visible_text('All')
time.sleep(3)
driver.find_element("class name","sprite-inter go-btn").click()
wait=WebDriverWait(driver,20)
driver.get('http://www.amfiindia.com/research-information/aum-data/classified-average-aum')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#divAumPeriod > span > a > span.ui-button-text"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH,"//*[#class='ui-menu-item']/a[.='January - 2022']"))).click()
Most of these tags open like so and have another list with them that's not using the select tag.
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
I am using Python selenium chromedriver and I want to add Capmonster to my code. Basically if my Code gets the URL, a ReCaptcha appears and I want to get it solved.
My Code
from threading import Thread
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
import os
chromedriver = 'C:\\Users\\yvesb\\OneDrive\\Desktop\\chromedriver\\chromedriver.exe'
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=options)
def test(driver, url):
driver.get(url)
try:
driver.save_screenshot('C:\\Users\\yvesb\\Downloads\\headless_chrome_test7.png')
finally:
print("screenshot done")
url = "https://www.snipes.com/login"
Thread(target=test, args=(driver, url)).start()
And when it gets the URL a ReCaptcha appears, which I want to get solved with my Capmonster Key.
I suggest you to try this library I've developed some time ago. If you have a set of labelled captchas that service would fit you. Take a look: https://github.com/punkerpunker/captcha_solver
In README there is a section "Train model on external data" that you might be interested in.
I want to attach file through below link. How can I do that using selenium python?
My code:
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
driver=webdriver.Chrome(executable_path="C:\Program Files (x86)\Drivers\chromedriver.exe")
driver.get("https://www.tascoutsourcing.com/job-openings/quality-assurance-engineer/")
driver.maximize_window()
time.sleep(10)
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.HOME)
driver.find_element_by_xpath("//*[#id='content']/div[2]/div[2]/div/div/div/div[1]/div/div/div/button").click()
driver.find_element_by_xpath("//*[#id='content']/div[2]/div[2]/div/div/div/section/div/form/div[3]/div[3]/div").click()
paul, please try to run below code - I have ran the same code in my system and it is working for me.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
action = ActionChains(driver)
driver.get("https://www.tascoutsourcing.com/job-openings/quality-assurance-engineer/")
# Click on Apply Button
Apply_btn = wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Apply Now']/parent::button")))
action.move_to_element(Apply_btn).click().perform()
time.sleep(2)
Upload_File = driver.find_element_by_xpath('/html/body/label/input').send_keys("YourFilePath")
Do let me know if it shows error.
I've written a script in python using selenium to scrape some text out of a webpage. The text I wanna scrape generates upon filling in an inputbox. My script can fill in in the right way and can populate the value. However, it can't parse the text. How can I do it?
This is what I've tried so far:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("http://dev.delshlearning.com.au/test.php")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#AM"))).send_keys("`(2(3^5-sqrt(3)))/2`",Keys.RETURN)
item = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR,"#MQ"))).text
print(item)
driver.quit()
The send_keys() parameter is already filled in within the script for your consideration.
It is storing the text values in the attribute value. This should work:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get("http://dev.delshlearning.com.au/test.php")
# I changed your locater to ID since it's a little more clear
wait.until(EC.visibility_of_element_located((By.ID,"AM"))).send_keys("`(2(3^5-sqrt(3)))/2`",Keys.RETURN)
item = wait.until(EC.visibility_of_element_located((By.ID,"MQ"))).get_attribute('value')
print(item)
driver.quit()
I found it by going to the element's properties as shown highlighted here: