0

I'm trying to execute a simple java script command at selenium using python for scroll a part of a web page.

Here's the code:

command_js = 'document.querySelector(' + "'" + 'css_div_example[css_example="this is just a example for css selector"]' + "').scroll(0, 10000)"
#string joined "document.querySelector('css_div_example[css_example="this is just a example for css selector"]').scroll(0, 10000)"
driver.execute_script(command_js)

Picture:

Picture of scroll bar

OBS.:

  • I tried to execute directly from Firefox console and it worked very well.
  • Selenium does not return any error, just not execute it.
  • I tried to WebDriverWait with EC and time.sleep().
  • I am using python 3+ and PyCharm IDE, Firefox webdrivers...

Anyone can help me?

  • Can't you just tell selenium to select something down on that div? – Rafael Braga Oct 12 '21 at 00:09
  • Contents of the div just appears if scroll down the bar :/ >pt-br: Então, os elementos da div só aparecem quando scrolla a barra, até consigo pegar os primeiros elementos, mas nem sempre vai ser o que preciso... – Iuri Wissmann Oct 12 '21 at 00:52
  • You're switching around quotes there... not sure of syntax for python, but it doesn't look right. You might need escape character... check here: https://stackoverflow.com/questions/9050355/using-quotation-marks-inside-quotation-marks – pcalkins Oct 12 '21 at 20:56
  • You dont need to see the element to select it. You can use: driver.find_element_by_xpath() – Rafael Braga Oct 14 '21 at 01:30
  • Podemos ir de ptbr se preferir. Você clica com o botão direito no elemento que quer que o selenium selecione e escolha "inspecionar". Depois clica na parte do código que tem o elemento e escolha: "copy > copy Xpath". Você vai copiar algo semelhante à: //*[@id="description"]/div/table/tbody/tr[1]/th e colar dentro do "find_element_by_xpath()" no seu código. Dá para usar outros elementos de css e dom para selecionar. – Rafael Braga Oct 14 '21 at 01:44
  • Dá uma olhada na documentação: https://www.selenium.dev/pt-br/documentation/support_packages/working_with_select_elements/ – Rafael Braga Oct 14 '21 at 01:45
  • @RafaelBraga Muito obrigado, usando o xpath consegui selecionar os elementos que eu queria. Valeu pelo seu tempo! – Iuri Wissmann Oct 17 '21 at 04:03

0 Answers0