Python - Selenium Locate elements by href

Python - Selenium Locate elements by href

Content Index :

Python - Selenium Locate elements by href
Tag : python , By : dummyadresse
Date : December 01 2020, 05:00 PM

this will help I am trying to find (and click) specific pages for my Python program using selenium. , You can try:
from selenium.webdriver.common.by import By
driver.find_element(By.PARTIAL_LINK_TEXT, 'text').click()
from selenium import webdriver
from selenium import webdriver

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to locate the href element using selenium python

Tag : python-2.7 , By : Matt Leacock
Date : March 29 2020, 07:55 AM
Does that help How to locate the href elements using selenium and python , To locate href attribute usually you can use

How to locate the four elements using selenium in python

Tag : python , By : ChristianM
Date : October 23 2020, 03:08 PM
wish helps you Since no one has posted a solution yet, here you go. You won't get far with requests, so selenium is your best choice here. If you want to use the below script without any modification, check that:
you are on linux or macos, or change dl_dir = '/tmp' to some directory you want you have chromedriver installed, or change the driver to firefox in code (and adapt the download dir configuration according to what firefox wants)
$ python -V
Python 3.5.3
$ chromedriver --version
ChromeDriver 2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2)
$ pip list --format=freeze | grep selenium
import os
import time
from selenium import webdriver
from selenium.webdriver.common import by
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import ui, expected_conditions as EC

def main():
    dl_dir = '/tmp'  # temporary download dir so I don't spam the real dl dir with csv files
    # check what files are downloaded before the scraping starts (will be explained later)
    csvs_old = {file for file in os.listdir(dl_dir) if file.startswith('NXSA-Results-') and file.endswith('.csv')}

    # I use chrome so check if you have chromedriver installed
    # pass custom dl dir to browser instance
    chrome_options = webdriver.ChromeOptions()
    prefs = {'download.default_directory' : '/tmp'}
    chrome_options.add_experimental_option('prefs', prefs)
    driver = webdriver.Chrome(chrome_options=chrome_options)
    # open page

    # wait for search ui to appear (abort after 10 secs)
    # once there, unfold the filters panel
    ui.WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((by.By.XPATH, '//td[text()="Observation and Proposal filters"]'))).click()
    # toggle observation availability dropdown
    driver.find_element_by_xpath('//input[@title="Observation Availability"]/../../td[2]/div/img').click()
    # wait until the dropdown elements are available, then click "proprietary"
    ui.WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((by.By.XPATH, '//div[text()="Proprietary" and @class="gwt-Label"]'))).click()
    # unfold display options panel
    driver.find_element_by_xpath('//td[text()="Display options"]').click()
    # deselect "pointed observations"
    # select "epic exposures"

    # uncomment if you want to go through the activated settings and verify them
    # when commented, the form is submitted immediately

    # submit the form
    # wait until the results table has at least one row
    ui.WebDriverWait(driver, 10).until(EC.presence_of_element_located((by.By.XPATH, '//tr[@class="MPI"]')))
    # click on save
    driver.find_element_by_xpath('//span[text()="Save table as"]').click()
    # wait for dropdown with "CSV" entry to appear
    el = ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((by.By.XPATH, '//a[@title="Save as CSV, Comma Separated Values"]')))
    # somehow, the clickability does not suffice - selenium still whines about the wrong element being clicked
    # as a dirty workaround, wait a fixed amount of time to let js finish ui update
    # click on "CSV" entry

    # now. selenium can't tell whether the file is being downloaded
    # we have to do it ourselves
    # this is a quick-and-dirty check that waits until a new csv file appears in the dl dir
    # replace with watchdogs or whatever
    dl_max_wait_time = 10  # secs
    seconds = 0
    while seconds < dl_max_wait_time:
        csvs_new = {file for file in os.listdir(dl_dir) if file.startswith('NXSA-Results-') and file.endswith('.csv')}
        if csvs_new - csvs_old:  # new file found in dl dir
            print('Downloaded file should be one of {}'.format([os.path.join(dl_dir, file) for file in csvs_new - csvs_old]))
        seconds += 1

    # we're done, so close the browser

# script entry point
if __name__ == '__main__':
Downloaded file should be one of ['/tmp/NXSA-Results-1509061710475.csv']

Python Selenium on IE not able to locate elements?

Tag : python , By : nemof
Date : March 29 2020, 07:55 AM
wish help you to fix your issue As per the HTML you have shared to send a character sequence to the desired element you can use either of the following solutions:
driver.find_element_by_css_selector("input.black_ar[name='mrn']").send_keys("Collette jorike")
driver.find_element_by_xpath("//input[@class='black_ar' and @name='mrn']").send_keys("Collette jorike")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.black_ar[name='mrn']"))).send_keys("Collette jorike")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='black_ar' and @name='mrn']"))).send_keys("Collette jorike")

Python and Selenium: Unable to locate a specific (href) element to click on

Tag : python , By : user150694
Date : March 29 2020, 07:55 AM
This might help you You can get all links using and . Code below print all 1000 links:
import requests
from bs4 import BeautifulSoup

base_url = "https://drugdesign.riken.jp/hERGdb"    
data = [
  ('smiles_S', ''),
  ('jme_S', ''),
  ('tab_selected', 'tab_S'),
  ('query_type', 'Substructure'),
  ('Target[]', 'hERG'),
  ('Target[]', 'Cav1.2'),
  ('Target[]', 'Nav1.5'),
  ('Target[]', 'Kv1.5'),
  ('Value_type[]', 'IC50'),
  ('Value_type[]', 'inhibition'),
  ('Value_type[]', 'other'),
  ('Assay_type[]', 'binding'),
  ('Assay_type[]', 'patch clamp'),
  ('Assay_type[]', 'other'),
  ('Data_source[]', 'ChEMBL'),
  ('Data_source[]', 'PubChem_CID'),
  ('Data_source[]', 'hERG Central(PubChem_SID)'),
  ('low_MW', ''),
  ('high_MW', ''),
  ('Assay_name', ''),
  ('Structure_Search', 'Search'),

response = requests.post(f'{base_url}/result.php', data=data)
lots = BeautifulSoup(response.text, "html.parser").select("a[href^='./compound.php?HGID=']")
for lot in lots:
    url = str(lot['href']).replace("./", "")

How to locate elements in a table with Python and Selenium?

Tag : python , By : user183345
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Probability mass function sum 2 dice roll?
  • Cannot call ubuntu 'ulimit' from python subprocess without using shell option
  • Dataframe Timestamp Filter for new/repeating value
  • Problem with clicking select2 dropdownlist in selenium
  • pandas dataframe masks to write values into new column
  • How to click on item in navigation bar on top of page using selenium python?
  • Add multiple EntityRuler with spaCy (ValueError: 'entity_ruler' already exists in pipeline)
  • error when replacing missing ')' using negative look ahead regex in python
  • Is there a way to remove specific strings from indexes using a for loop?
  • select multiple tags by position in beautifulSoup
  • pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • How to calculate each single element of a numpy array based on conditions
  • How do I change the width of Jupyter notebook's cell's left part?
  • Measure distance between lat/lon coordinates and utm coordinates
  • Installing megam for NLTK on Windows
  • filter dataframe on each value of a samn column have a specific value of another column in Panda\Python
  • Threading with pubsub throwing AssertionError: 'callableObj is not callable' in wxPython
  • Get grouped data from 2 dataframes with condition
  • How can I import all of sklearns regressors
  • How to take all elements except the first k
  • Whats wrong with my iteration list of lists from csv
  • Tensorflow Estimator API save image summary in eval mode
  • How to Pack with PyQt - how to make QFrame/Layout adapt to content
  • How do I get certain Time Range in Python
  • python doubly linked list - insertAfter node
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com