python – Deem dicas de como usar o Selenium para comentar o @ dos seguidores

Como posso fazer pra comentar o @ dos meus seguidores do Instagram numa certa postagem usando Selenium? Tipo, o bot precisaria verificar se a pessoa me segue e se eu sigo a sigo de volta, caso seja verdade eu comento o @ dela na postagem. E aí eu comento todos os @ que seguem essa regra até acabar, sem se repetir. Preciso de uma dica de como fazer ou um link que possa me ajudar a fazer isso, agradeço desde já!

c# – Funções de busca do Selenium agem mais rapido que o carregamento da pagina

Estou tentando automatizar uma função, para que após o Login na pagina sejam executadas determinadas funções. Porém, após clicar em “Login” o botão que deveria ser clicado, ainda não terminou de carregar e o Selenium acusa o seguinte erro: OpenQA.Selenium.NoSuchElementException.

Estou tentando com Implicit e Explicit Wait porém não estou conseguindo “forçar” essa espera.

Detalhes: Preciso realizar essa espera sem o comando Thread.Sleep(MILISEGUNDOS);

Estou realizando a busca por Xpath pois o elemento não possui Id

Aqui o modelo de busca que estou usando atualmente.

var btnSystem = new WebDriverWait(driver, TimeSpan.FromSeconds(15)).Until(drv => drv.FindElement(By.Xpath("/html/body/div/div/div(2)/div/div(2)/div/div(2)/div/a(8)/div")));
btnSystem.Click();

Selenium no modo Headless não encontra elementos da pagina (Python)

Meu codigo funciona normalmente sem o headless ativado, mas assim que eu ativo ele para de funcionar, é como se ele não encontrasse o elemento na pagina.

O problema não é no codigo do headless, pois ja mandei ele tirar print e funciona normamente, o problema se da a partir do momento que eu tento encontrar algum elemento da pagina

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from time import sleep

options = webdriver.ChromeOptions()
options.add_argument('--headless')

navegador = webdriver.Chrome(chrome_options=options)
navegador.get('https://www.instagram.com/')

insta = 'user'
senha2 = 'senha'

sleep(3)

login = navegador.find_element_by_xpath('//*(@id="loginForm")/div/div(1)/div/label/input')
login.send_keys(insta)

sleep(2)
psw = navegador.find_element_by_name('password')
psw.send_keys(senha2)

sleep(2)
btn_logar = navegador.find_element_by_css_selector('.sqdOP.L3NKy.y3zKF')
btn_logar.click()

sleep(6)
navegador.save_screenshot('insta.png')

spring boot – What is the best approach to do a end-to-end test using selenium webdriver and junit5?

Since selenium can’t do rest call testing and since I found a lot of different interpretations of an integration test, I am having trouble understanding what is the correct approach to test my spring boot api using selenium and junit5.

For an example, if I were to have a button in my frontend that when clicked sends a rest call to the server how should I test the validity of the response? Initial idea was to make two calls, one using selenium, one using MockMvc and compare the responses, though I can’t seem to find a way to get the webdriver response. Or do I have to check instead for some changes on the frontend, also if I do that approach is it still an end-to-end test?

Also, considering I am not going to implement every single layer of abstraction (meaning the controller, service and repository) is MockMvc test approach enough for the test to qualify as an integration test or is it still a unit test?

Any explanation or code example would be much appreciated.

Error en get_download_path() usando selenium con python

Muy buenas a todos estoy aprendiendo sobre scraping y crawling en python con Beautifulsoup4 y selenium.
De momento va bien pero me encuentro atascado. Es la primera vez que hago una pregunta aqui, no estoy seguro de si poner solo parte del codigo o todo, asique ante la duda mejor que sobre a que falte.

import zipfile, os, time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys



driver = webdriver.Chrome('c:/Users/brais/Desktop/python/navegador/chromedriver.exe')
driver.get('http://eportal.mapa.gob.es/websiar/SeleccionParametrosMap.aspx?dst=1')


string_ccaa = 'select(name="ctl00$ContentPlaceHolder1$DropDownListCCAA") option(value="8")'
desplegable_ccaa = driver.find_element_by_css_selector(string_ccaa)
click_desplegable_ccaa = desplegable_ccaa.click()

time.sleep(2)

string_ccaa = 'select(name="ctl00$ContentPlaceHolder1$DropDownListProvincia") option(value="44")'
desplegable_prov = driver.find_element_by_css_selector(string_ccaa)
click_desplegable_ccaa = desplegable_prov.click()

time.sleep(2)

agregar_estacion = driver.find_element_by_css_selector('input(name="ctl00$ContentPlaceHolder1$ButtonAgregar")')
click_agregar = agregar_estacion.click()

time.sleep(2)

consulta_datos = driver.find_element_by_css_selector('input(name="ctl00$ContentPlaceHolder1$btnConsultar")')
click_consulta = consulta_datos.click()

time.sleep(2)

driver.switch_to.window(driver.window_handles(1))
exportar_csv_link = driver.find_element_by_css_selector('a(id="ContentPlaceHolder1_ExportarCSV")')
descargar_csv = exportar_csv_link.click()

time.sleep(2)

driver.quit()

zip_ref = zipfile.ZipFile(get_download_path()+'/InformeDatos.zip', 'r')
zip_ref.extractall("Resultados/")
zip_ref.close()
os.remove(get_download_path()+'/InformeDatos.zip')

El error que me saca por consola es el siguiente.

DevTools listening on ws://127.0.0.1:58230/devtools/browser/00da0ce8-bcb0-4855-a775-c43ea816bb18
Traceback (most recent call last):
  File "navegadorweb.py", line 41, in <module>
    zip_ref = zipfile.ZipFile(get_download_path()+'/InformeDatos.zip', 'r')
NameError: name 'get_download_path' is not defined

¿Como puedo solucionar el error? ¿Hay algun otro posible error en el codigo?
De antemano gracias por la ayuda.

How to make selenium in python faster

I’m making a bot for PlayStation 5.
And restock is coming soon so I want to make my bot faster.
The approximate duration is 4.90 seconds.
Is there any way to make this faster?
I found that I should write this in C or C ++ for better results.

#startup
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver = webdriver.Chrome('chromedriver')
driver.maximize_window()
driver.get("https://www.games.rs/ps4-konzole/16794-konzola-playstation-4-1tb-pro-black-dualshock-fifa-21")

Cena and Kupi are unnecessary.
Program clicks to accept cookies.
Then scrolling cuz it needs to.
And then refreshing page until text in button is “Add to Cart”.

#order
start_time = time.time() 
kupi = driver.find_element_by_xpath('//*(@class="block product-attributes-wrapper clearfix")/ul(1)/li(1)/div(1)/div(1)')
cena = driver.find_element_by_xpath('//*(@class="block product-attributes-wrapper clearfix")/ul(1)/li(1)/div(1)/div(1)')
driver.find_element_by_xpath('//*(@id="modal-cookie-info")/div/div/div/div/button').click()
driver.execute_script("window.scrollTo(712, 200);", kupi)
while True:
    try:
        driver.find_element_by_xpath('//button(text()="Dodaj u korpu")')
    except NoSuchElementException:
        driver.refresh()
    else:
        driver.find_element_by_xpath('//button(text()="Dodaj u korpu")').click()
        break

driver.find_element_by_xpath('//*(@id="miniCartContent")/div(1)/a').click()
driver.execute_script("window.scrollTo(0 , 900);", )

Lastly login for informations and completing order.

#login
driver.find_element_by_xpath('//*(@id="order_address_content")/div/div/div(2)/div(2)/div(1)/div(1)/div(2)/div/div/a').click()
time.sleep(0.2)
email = driver.find_element_by_css_selector('#login_email')
email.send_keys("mail")

password = driver.find_element_by_id('login_password')
password.send_keys("pass")
driver.find_element_by_xpath('//*(@id="login_modal")/div/div/form/div(3)/button').click()
time.sleep(0.2)
driver.execute_script("window.scrollTo(0 , 1600);", )
driver.find_element_by_xpath('//*(@class="delivery-options list-unstyled")/li(3)/div(1)/div(1)').click()
time.sleep(0.5)
driver.execute_script("window.scrollTo(0 , 2500);", )
driver.find_element_by_xpath('//*(@id="submit_order_one_page")').click()

This prints duration of the program.

print("--- %s seconds ---" % (time.time() - start_time))

python – Como executar scripts no F12 pelo Selenium

Eu queria saber como faço pra executar um script pelo F12 ( Ferramentas de Desenvolvedor ) pelo Selenium, eu queria que ele abrisse o F12, depois iria até o Console e lá colocar lá o script, eu já tentei driver.execute_script(‘script’), mais só funciona se eu tiver o F12 aberto no Google.

O que eu tenho até agora é isso

from selenium import webdriver


browser = webdriver.Chrome()
browser.get(URL_SITE)

browser.execute_script("var iframe = document.createElement('iframe');iframe.onload = function(){var ifrLocalStorage = iframe.contentWindow.localStorage; return ifrLocalStorage.getItem('token');};iframe.src = "https://pt.stackoverflow.com/about:blank";document.body.appendChild(iframe);")

c# – Capturar dados de um grid com Selenium WebDriver

Galera, tenho um software que capta dados do Magento e os processa. Contudo, preciso pegar os dados de uma tabela e não sei como fazer.

A estrutura da tabela é assim, como posso capturar?

<div class="grid np">
<div class="hor-scroll">
<table cellspacing="0" class="data order-tables">
<colgroup><col>
<col width="1">
<col width="1">
<col width="1">
<col width="1">
<col width="1">
<col width="1">
<col width="1">
<col width="1">
<col width="1">
</colgroup><thead>
<tr class="headings">
<th>Produto</th>
<th><span class="nobr">Status do Produto</span></th>
<th><span class="nobr">Preço Original</span></th>
<th>Preço</th>
<th class="a-center">Qtd</th>
<th>SubTotal</th>
<th><span class="nobr">Valor do Imposto</span></th>
<th><span class="nobr">Percentual do Imposto</span></th>
<th><span class="nobr">Valor do Desconto</span></th>
<th class="last"><span class="nobr">Linha Total</span></th>
</tr>
</thead>
<tbody class="even">
<tr class="border">
<td>
<div id="order_item_81931" class="item-container">
<div class="item-text">
<h5 class="title"><span id="order_item_81931_title">Bermuda Moletom Jet Preto</span></h5>
<div><strong>SKU:</strong> 0035-BJ-egg</div>
<dl class="item-options">
<dt>Tamanho</dt>
<dd>
EGG </dd>
</dl>
</div>
</div>
</td>
<td class="a-center">Faturado</td>
<td class="a-right"><span class="price">R$57,72</span></td>
<td class="a-right">
<span class="price-excl-tax">
<span class="price">R$57,72</span>
</span>
<br>
</td>
<td><table cellspacing="0" class="qty-table">
<tbody><tr>
<td>Solicitado</td>
<td><strong>2</strong></td>
</tr>
<tr>
<td>Faturado</td>
<td><strong>2</strong></td>
</tr>
</tbody></table>
</td>
<td class="a-right">
<span class="price-excl-tax">
<span class="price">R$115,44</span>
</span>
<br>
</td>
<td class="a-right"><span class="price">R$0,00</span></td>
<td class="a-right">0%</td>
<td class="a-right"><span class="price">R$0,00</span></td>
<td class="a-right last">
<span class="price">R$115,44</span> </td>
</tr>
</tbody>
<tbody class="odd">
<tr class="border">
<td>
<div id="order_item_81933" class="item-container">
<div class="item-text">
<h5 class="title"><span id="order_item_81933_title">Bermuda Dry-Fit Floral Black Knulu</span></h5>
<div><strong>SKU:</strong> 9574-CD-egg</div>
<dl class="item-options">
<dt>Tamanho</dt>
<dd>
EGG </dd>
</dl>
</div>
</div>
</td>
<td class="a-center">Faturado</td>
<td class="a-right"><span class="price">R$87,96</span></td>
<td class="a-right">
<span class="price-excl-tax">
<span class="price">R$87,96</span>
</span>
<br>
</td>
<td><table cellspacing="0" class="qty-table">
<tbody><tr>
<td>Solicitado</td>
<td><strong>1</strong></td>
</tr>
<tr>
<td>Faturado</td>
<td><strong>1</strong></td>
</tr>
</tbody></table>
</td>
<td class="a-right">
<span class="price-excl-tax">
<span class="price">R$87,96</span>
</span>
<br>
</td>
<td class="a-right"><span class="price">R$0,00</span></td>
<td class="a-right">0%</td>
<td class="a-right"><span class="price">R$0,00</span></td>
<td class="a-right last">
<span class="price">R$87,96</span> </td>
</tr>
</tbody>
<tbody class="even">
<tr class="border">
<td>
<div id="order_item_81935" class="item-container">
<div class="item-text">
<h5 class="title"><span id="order_item_81935_title">Camiseta Estampada Keep Quiet Greek Knulu Preta</span></h5>
<div><strong>SKU:</strong> 1926-B-g2</div>
<dl class="item-options">
<dt>Tamanho</dt>
<dd>
G2 </dd>
</dl>
</div>
</div>
</td>
<td class="a-center">Faturado</td>
<td class="a-right"><span class="price">R$46,16</span></td>
<td class="a-right">
<span class="price-excl-tax">
<span class="price">R$46,16</span>
</span>
<br>
</td>
<td><table cellspacing="0" class="qty-table">
<tbody><tr>
<td>Solicitado</td>
<td><strong>1</strong></td>
</tr>
<tr>
<td>Faturado</td>
<td><strong>1</strong></td>
</tr>
</tbody></table>
</td>
<td class="a-right">
<span class="price-excl-tax">
<span class="price">R$46,16</span>
</span>
<br>
</td>
<td class="a-right"><span class="price">R$0,00</span></td>
<td class="a-right">0%</td>
<td class="a-right"><span class="price">R$0,00</span></td>
<td class="a-right last">
<span class="price">R$46,16</span> </td>
</tr>
</tbody>
</table>
</div>
</div>

python – Selenium Webdriver Timeout Exception on Heroku and Pythonanywhere both

i am working on an project in which my script takes screenshot of tweet code is working on local server but i am getting timeout exception error on heroku and pythonanywhere both platforms.. i have tried changing code many times, this is the code i have uploaded on heroku attached to this question

from flask import Flask, render_template, request, url_for, redirect,session,send_file
from selenium import webdriver
import os
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")


app = Flask(__name__,
            static_url_path='', 
            static_folder='static',
            template_folder='templates'
)
app.config('SEND_FILE_MAX_AGE_DEFAULT') = 0
app.secret_key = "Super Secret Key"

@app.route("https://cs.stackexchange.com/")
def index():
   if 'success' in session:
      session.pop('success',None)
      return render_template('index.html',success=True)
   elif 'error' in session:
      session.pop('error',None)
      return render_template('index.html',error=True)
   elif 'file' in session:
      session.pop('file',None)
      return send_file("static/images/screenshot.png",as_attachment=True)
   else:
      return render_template('index.html')

@app.route('/check',methods = ('POST', 'GET'))
def check():
   if request.method == 'POST':
      try:
         download = request.form('auto_download')
         download = True
      except:
         download = False
      try:
         driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"),options=chrome_options)
         url = request.form('url')
         #driver.implicitly_wait(30)
         driver.get(url)
         wait = WebDriverWait(driver, 10)
         element = wait.until(EC.element_to_be_clickable((By.TAG_NAME, 'article')))
         elem = driver.find_element_by_tag_name("article")
         elem.screenshot("static/images/screenshot.png")
         driver.close()
         if download == True:
            session('file') = "True"
            return redirect(url_for("index"))
         else:
            session('success') = "True"
            return redirect(url_for("index"))
      except Exception as err:
         return f"{err.__class__.__name__}: {err}"
         #session('error') = "True"
         #return redirect(url_for("index"))
   else:
      return redirect(url_for('index'))


if __name__ == '__main__':
   app.run()

software – How do Top Companies handle Writing Tags for Selenium?

Does Anyone know if Google, Facebook, Amazon, and other top FAANG companies use automation tags in their web projects? We have literally hundreds of Pages, Buttons, Textboxes, and its very tedious to write the tags across application. We still use Selenium, however wondering what the top companies do now these days?

This article was written 7 years ago.

Is adding IDs to everything standard practice when using Selenium?