I am trying to make a tiktok bot, but I am having issues entering in text to their caption section(see screenshot below). I've tried using wait till element clickable function, but for some reason I can not use selenium to detect this element, would anyone have any suggestions on how to go about this, thank you in advance :)
My current code is below:
driver.get("https://www.tiktok.com/upload?lang=en")
try:
element = WebDriverWait(driver, waittime).until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#root > div > div > div > div > div.jsx-410242825.contents-v2 > div.jsx-2580397738.form-v2 > div.jsx-2580397738.caption-wrap-v2 > div > div:nth-child(1) > div.jsx-1717967343.margin-t-4 > div > div.jsx-1043401508.jsx-723559856.jsx-1657608162.jsx-3887553297.icon-style.hash')))
except:
driver.quit()
element.click()
try:
element = WebDriverWait(driver, waittime).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#root > div > div > div > div > div.jsx-410242825.contents-v2 > div.jsx-2580397738.form-v2 > div.jsx-2580397738.caption-wrap-v2 > div > div:nth-child(1) > div.jsx-1717967343.margin-t-4 > div > div.jsx-1043401508.jsx-723559856.jsx-1657608162.jsx-3887553297.editor > div > div > div > div > div > div > span > span > span')))
except:
driver.quit()
element.clear()
element.send_keys(mainCaption)
Element snapshot:
HTML <br> Tag
The <br> tag inserts a single line break. The <br> tag is an empty tag which means that it has no end tag and is useful for writing addresses or poems to enter line breaks, not to add space between paragraphs. Hence, you can't send any text within a <br> element.
Presumably, <br> tags will have parent/ancestor <p> tags. As an example:
<p>Be not afraid of greatness.<br>
Some are born great,<br>
some achieve greatness,<br>
and others have greatness thrust upon them.</p>
<p><em>-William Shakespeare</em></p>
So in these cases you need to target the parent/ancestor <p> tags to send the text.
I am trying to set a variable to then use later on in an assert. I want to verify a date on one page is the same on another page. I have the below;
cy.get("#due > div > div > div > input").then(($dueDatePicker) => {
const dueDate = $dueDatePicker.text();
cy.log(dueDate);
});
I then have the below assert later on in the test;
cy.get("#content > div > section.content.mtm10 > div.row > div > div > div.box-body").contains(dueDate);
However Cypress tells me dueDate is undefined in the Assert.
What am I missing? Thanks
There is a scoping issue with where you are defining the variable. There are a few ways to get around this.
The first would be to declare the variable outside of the Cypress chain.
let dueDate = ''
cy.get('foo')
.then(($el) => {
dueDate = $el.text()
})
.get('bar').contains(dueDate);
You could also return the value from the .then().
cy.get('foo')
.then(($el) => {
return $el.text();
})
.then((dueDate) => {
cy.get('bar').contains(dueDate);
})
I'd recommend Filip Hric's blogpost on Cypress variables for more information on understanding how the variables/scopes/timing all work together.
As long as you are using the value later in the same test, an alias is the preferred way to store a result for a later assertion
cy.get("#due > div > div > div > input")
.invoke('text')
.as('dueDate')
...
cy.get('#dueDate').then(dueDate => {
cy.get("#content > div > section.content.mtm10 > div.row > div > div > div.box-body")
.contains(dueDate)
})
Writing steps for UI testing using karate framework
so basically svg button, have to click then the URL in the new tab for further functionality processing
how to handle that ?
i tried below code
def secure_url = mouse("#root > section > section > main > div > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody > tr:nth-child(1) > td:nth-child(7) > span > button > svg").click()
and verified the secure_url value using
print secure_url
it prints com.intuit.karate.driver.DriverMouse#664e5dee
but Expected is URL
Most Karate methods will return an Element object on which you have to call more methods. Please spend some time to read the docs: https://github.com/intuit/karate/tree/master/karate-core#chaining
* def elem = locate('#some-id')
* def url = elem.attribute('href')
I have a list of objects on my site that all have 'Add' buttons next to them. When the first 'Add' button is clicked, that object is added and the row disappears and is replaced by the next one down. The object name is the same. I want to .click() three times to add the first three objects in the list, before saving. How can I do this?
I'm aware of .click() to click a single object. I'm also aware of .click ({ multiple: true}) to click all the objects on the page. However, I want it to stop clicking after the third time.
Currently set to click multiple times to add all the objects in the list (which is incorrect):
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.should('exist')
.click({ multiple: true });
To hammer click a button you can use this:
for(let n = 0; n < 10; n ++){
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.click()
}
The multiple: true is used to click several elements, for example to click all buttons on the page.
If you need just a few clicks you could also go for this great solution:
cy.get("button").click().click().click()
.click().click().click().click().click()
.click().click()
In my opinion this syntax also gives a great sensation of what the user would be doing in this scenario.
The problem is with your selector. If you have n number of buttons, and you want to click all of them, then you need to match all the buttons, not just a single one. So look for a selector (e.g. a class unique to your Add button) that matches all of them.
You can then use .each() to iterate through them and break out of the loop when you reach a certain index:
cy.get('#your_selector_to_your_add_buttons')
.each(($el, $index) => {
if($index == 3){
return false;
}
cy.wrap($el).click()
} )
You just had to move your assertion after the click and said click until not exists
.click({ multiple: true })
.should('not.exist');```
you could use lodash
https://lodash.com/docs/4.17.15#times
import { times } from 'lodash'
times(2, () => {
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.click()
})
You could also do like this:
Cypress._.times(10, () => {
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button').click()
})
The best way I could find to do this was by using the Wait for a number of milliseconds or wait for an aliased resource to resolve before moving on to the next command.
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.should('exist')
.click();
cy.wait(500)
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.should('exist')
.click();
cy.wait(500)
cy.get('#FieldListDialog > div > table > tr > td > button.button.add-button')
.should('exist')
.click();
Following the comments by Kamran Eyyubov and monikapatelIT, I was able to come up with the following to simulate a button mash, using the Lodash library that cypress exposes.
// Fetch a reference outside the loop so it can be referenced inside the
// loop.
cy.get('#submit-button')
.as('submitButton');
// Simulate a button mash. Click the button 10 times.
Cypress._.times(10, function () {
cy.get('#submitButton')
// The submit button is disabled on the first click, so
// force is set to TRUE to prevent the test from failing
// due to clicking a disabled element.
.click({force: true});
});
// option 1
cy.get('button')
.dblclick()
// option 2
cy.get('button')
.click({ multiple: true })
I did and command
Cypress.Commands.add('MultiClick',(element:string,times: number) => {
for(let n = 0; n < times; n ++){
cy.get(element).click({ force: true })
}
})
and then use it
cy.MultiClick('[data-cy=qty-product]',2)
[header files[][1]1seelnium webdriver
error
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/support/ui/Select (wrong name: org/openqa/selenium/support/ui/select)
Code tried:-
Select select = new Select(driver.findElement(By.cssSelector("body > app-root > app-patient-index > app-patient-profile > div.s_detail_doc_wrapper > div.s_patient_detail_tab > div > tabset > div > tab.active.tab-pane > form > div > div.s_patient_profile_form > div > div.col-md-9 > ul > li:nth-child(2) > div > div.col-md-9 > div > div.col-sm-5.pl0 > select")));
select.deselectAll();
select.selectByVisibleText("Married");
enter image description here
enter image description here
Please use the below code to select the value from the dropdown.
Note: If the dropdown is of type select.
import to be used is.
import org.openqa.selenium.support.ui.Select;
System.setProperty("webdriver.chrome.driver","Drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.facebook.com/");
Thread.sleep(3000);
Select dayDropDown = new Select(driver.findElement(By.xpath("//select[#name='birthday_day']")));
dayDropDown.selectByVisibleText("5");
Missing Select class is found inside elenium-support jar which you are missing.
You can download jar directly for example for version 2.0a7 from :
http://central.maven.org/maven2/org/seleniumhq/selenium/selenium-support/2.0a7/selenium-support-2.0a7.jar
Or add maven dependencies
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-support -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.0a7</version>
</dependency>